Say I create a table People using this:
rails new app; cd app; rails g scaffold Person name:string; rake db:migrate
and then try setting the name for a row using:
rails console
Loading development environment (Rails 3.2.3)
1.9.2p318 :001 > @person = Person
=> Person(id: integer, name: string, created_at: datetime, updated_at: datetime)
1.9.2p318 :002 > @person.name = "test"
NoMethodError: undefined method `name=' for #<Class:0x007f9b8d807098>
Why does the last line fail with an undefined method?
Your
@person = Personis literally saying @person is the Person class.You should use
@person = Person.new(). You can assign attributes now because the instance variable is a new Person object.