[英]Cannot create new object for Ruby on Rails model
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 但是,当我尝试在控制台中创建新对象时,标题和内容字段始终显示为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
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.