When I add
attr_accessor :minor_edit, :title, :body, :slug, :domain_id
in my Post model, when I save the model by
post = Post.new(:title => "123", body => "456")
post.save
The database said the title column is null
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you set
attr_accessor :titleyou override ActiveRecords setter method. You want to useattr_accessibleinstead to stop mass assignment.http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html