simple question. I'm trying to create a new object for a very basic class
class Article < ActiveRecord::Base
attr_accessor :title, :content
validates :title, :presence => true
validates :content, :presence => true
end
However, when I try to create a new object in the console, the title and content fields always show up as nil
1.9.2-head :021 > a = Article.new(title: "abcdefg", content: "hijklmnop")
=> #<Article id: nil, title: nil, content: nil, created_at: nil, updated_at: nil>
Why can't I create a new object?
你试图使用attr_accessible
吗?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.