Ruby on rails Rails窗体参数在控制器中更改

Ruby on rails Rails窗体参数在控制器中更改,ruby-on-rails,ruby-on-rails-3,params,Ruby On Rails,Ruby On Rails 3,Params,我有一张表格: <%= form_for(:report_main, :url => {:action => 'exporttoxiccreate'}) do |f| %> <%= collection_select(:waste, :code, Waste.find_all_by_istoxic(false), :id, :code, :include_blank => '') %> <%= f.check_box(:q_pripadnost)

我有一张表格:

<%= form_for(:report_main, :url => {:action => 'exporttoxiccreate'}) do |f| %>
<%= collection_select(:waste, :code, Waste.find_all_by_istoxic(false), :id, :code, :include_blank => '') %>
<%= f.check_box(:q_pripadnost) %>
<%= f.text_field(:amount) %>
<% end %>
我想将此表单中的数据保存在两个表中,两个对象中,并且我需要分离要处理的参数。我试过这个:

@reportexport.q_pripadnost = @reportparam.q_pripadnost
我想在@reportexport中用param中的一些值设置q_pripadnot字段。


我哪里出错了?

当您从Rails中的表单获取参数时,它以散列的形式出现。例如:

params[:report_main][:waste]
params[:report_main][:amount]
def exporttoxiccreate
    @reportparam = params[:report_main]
    render :text => @reportparam.to_yaml
end
因此,当您调用
@reportparam=params[:report_main]
时,您将
@reportparam
设置为散列,但稍后您将尝试将其作为对象使用。例如,使用
@reportparam[:q_pripadnost]
代替
@reportparam.q_pripadnost

通过临时更改操作以显示变量的文本版本,可以更仔细地查看变量,例如:

params[:report_main][:waste]
params[:report_main][:amount]
def exporttoxiccreate
    @reportparam = params[:report_main]
    render :text => @reportparam.to_yaml
end

当您从Rails中的表单获取参数时,它以散列的形式出现。例如:

params[:report_main][:waste]
params[:report_main][:amount]
def exporttoxiccreate
    @reportparam = params[:report_main]
    render :text => @reportparam.to_yaml
end
因此,当您调用
@reportparam=params[:report_main]
时,您将
@reportparam
设置为散列,但稍后您将尝试将其作为对象使用。例如,使用
@reportparam[:q_pripadnost]
代替
@reportparam.q_pripadnost

通过临时更改操作以显示变量的文本版本,可以更仔细地查看变量,例如:

params[:report_main][:waste]
params[:report_main][:amount]
def exporttoxiccreate
    @reportparam = params[:report_main]
    render :text => @reportparam.to_yaml
end