I created a basic scaffold for a Foo model with a single property - bar:String
foos/new.html.erb:
<h1>New foo</h1>
<% form_for(@foo) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :bar %><br />
<%= f.text_field :bar %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', foos_path %>
But I get a NoMethodError for my 'bar' property:
NoMethodError in Foos#new
Showing app/views/foos/new.html.erb where line #8 raised:
undefined method `bar' for #<Foo id: nil, created_at: nil, updated_at: nil>
Extracted source (around line #8):
5:
6: <p>
7: <%= f.label :bar %><br />
8: <%= f.text_field :bar %>
9: </p>
10: <p>
11: <%= f.submit 'Create' %>
As you can see, bar the only property in my Foo model:
class CreateFoos < ActiveRecord::Migration
def self.up
create_table :foos do |t|
t.String :bar
t.timestamps
end
end
def self.down
drop_table :foos
end
end
And the new method in the foos_controller is from the default scaffold:
def new
@foo = Foo.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @foo }
end
end
Any ideas would be appreciated