Eric Baldwin
Eric Baldwin

Reputation: 3491

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

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?

Upvotes: 0

Views: 1314

Answers (1)

James
James

Reputation: 4807

Were you trying to use attr_accessible?

Upvotes: 2

Related Questions