我试图在Rails数据库银行应用程序上添加一个新事务,但是当我单击new时,会得到以下错误:
显示app/views/transactions/_transaction_form.html.erb #10行的Transactions#new中的
NoMethodError :未定义的方法“`dateD”表示#
在第10行周围,即:
9: <%= f.label :dateD %><br />
10: <%= f.date_select :dateD %>它似乎是错误的,即使我删除了这个,但有不同的错误。这里是我的_transaction_form.html.erb,我在我的编辑/新页面上使用这个,编辑看起来很好,但是一旦我进入new,我就会得到上面发布的错误。以下是新版本的代码:
_transaction_form.html.erb
<% form_for(@bank_account,@transaction) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :bank_account_id %><br />
<%= f.text_field :bank_account_id %>
</p>
<p>
<%= f.label :dateD %><br />
<%= f.date_select :dateD %>
</p>
<p>
<%= f.label :trans_type %><br />
<%= f.text_field :trans_type %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :new_balance %><br />
<%= f.text_field :new_balance %>
</p>
<p>
<%= f.label :transaction_success %><br />
<%= f.check_box :transaction_success %>
</p>
<p>
<%= f.submit 'Submit' %>
</p>
<% end %>TransactionsController#new
def new
@transaction = @bank_account.transactions.build
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @transaction }
end
end发布于 2012-03-15 02:27:01
两件事。您的form_for应该使用<%=而不是<%,并且应该在@bank, @transaction部件周围使用[]:
<%= form_for([@bank_account,@transaction]) do |f| %>https://stackoverflow.com/questions/9712777
复制相似问题