我想在rails上通过form_for传递与模型无关的参数。我想从视图到控制器传递与产品模型无关的“地址”数据。以下是我的代码,但是它返回了下一个错误。你能告诉我如何解决这个问题吗?
在11ms内完成500内部服务器错误(ActiveRecord:0.1ms) ActionView :: Template :: Error(错误的参数数量(1为2..5)):
products_controller
class ProductsController < ApplicationController
~~~~
def transfer
@product = Product.new
end
def transfer_done
my_address = params[:my_address]
wallet = Wallet.find_by(address:my_address)
redirect_to root_url
end
~~~~
end
transfer.html.erb
<% provide("transfer") %>
<p>
<%= form_for @product, :url => {:action => 'transfer_done'} do |f| %>
<div>
<%= check_box :my_address %> <---Error occurred here.
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
</p>
答案 0 :(得分:2)
您可以在表单中尝试<%= text_field_tag :my_address %>