提交 e8b26258 编写于 作者: S Steve Klabnik

Getting Started: remove reference to attr_accessible

上级 8bc945da
......@@ -693,7 +693,6 @@ The model file, `app/models/post.rb` is about as simple as it can get:
```ruby
class Post < ActiveRecord::Base
attr_accessible :text, :title
end
```
......@@ -703,12 +702,6 @@ your Rails models for free, including basic database CRUD (Create, Read, Update,
Destroy) operations, data validation, as well as sophisticated search support
and the ability to relate multiple models to one another.
Rails includes methods to help you secure some of your model fields. The Rails
model generator added the `attr_accessible` line to your model file. This change
will ensure that all changes made through HTML forms can edit the content of
the text and title fields. Accessible attributes and the mass assignment problem is covered in
details in the [Security guide](security.html#mass-assignment)
### Adding Some Validation
Rails includes methods to help you validate the data that you send to models.
......@@ -716,8 +709,6 @@ Open the `app/models/post.rb` file and edit it:
```ruby
class Post < ActiveRecord::Base
attr_accessible :text, :title
validates :title, presence: true,
length: { minimum: 5 }
end
......@@ -1229,7 +1220,6 @@ First, take a look at `comment.rb`:
```ruby
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :body, :commenter
end
```
......@@ -1292,7 +1282,6 @@ makes each comment belong to a Post:
```ruby
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :body, :commenter
end
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册