我創建了一個基本骨架的富模型單個屬性 - 條:字符串基本腳手架視圖中的NoMethodError?
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 %>
但我得到一個NoMethodError我的酒吧「屬性:
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' %>
正如你可以看到,酒吧唯一的財產在我的富模式:
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
而在foos_controller的新方法是從默認腳手架:
def new
@foo = Foo.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @foo }
end
end
任何想法,將不勝感激
試過,但是當我檢查數據庫時沒有欄柱。想想我要刪除這個項目並重新開始。 – toma 2009-09-29 15:42:25