I'm making a banner system where I can upload a banner to a CampaignBanner ( with description, url and position ).
我正在做一个横幅系统,在那里我可以上传一个横幅到一个竞选横幅(有描述,url和位置)。
In the view I build the form like this :
在视图中,我构建这样的表单:
.page-header
%h1= t(:'.market_place.title')
.row-fluid
= form_tag update_dashboard_banners_admin_dashboard_index_path, :method => :put do
%fieldset
- @dashboard_banners.each do |dashboard_banner|
.span3
= simple_fields_for "dashboard_banners[]", dashboard_banner do |db|
= db.input :description
= db.input :target
= db.input :target_url
- dashboard_banner.build_banner if dashboard_banner.banner.nil?
= db.fields_for :banner do |f|
= f.input :data, :as => :file
%p= submit_tag t(:'buttons.update'), :class => 'btn btn-primary'
But when I submit the form I got
但是当我提交表单时。
expected Array (got Rack::Utils::KeySpaceConstrainedParams) for param dashboard_banners
用于param dashboard_banner的预期数组(获得机架:Utils::KeySpaceConstrainedParams)
For example in my first fields_for I get in name for target_url :
例如,在我的第一个fields_for中,我获得了target_url的名称:
dashboard_banners[21][target_url]
dashboard_banners[21][target_url]
There I have my id but in the second fields for my banner I have :
我有我的id,但在我的banner的第二个字段中,我有:
dashboard_banners[][banner_attributes][data]
dashboard_banners[][banner_attributes](数据)
Here you can see that I don't have the number 21 anymore.
这里你可以看到我不再有21了。
Is this linked to the internal server I got?
这个链接到我的内部服务器了吗?
1 个解决方案
#1
2
I encountered the same error then I renamed the name of the checkbox array to something else other than the name of the model. It worked.
我遇到了相同的错误,然后将复选框数组的名称重命名为除模型名称之外的其他名称。它工作。
For example you have @dashboard_banners as your model then you call your checkbox dashboard_banners[]. I think that causes the error. Name it to something else like d_banner[] then fetch ii in the controller as params[:d_banner]. Then you can loop it in the controller or do anything that you like.
例如,您将@dashboard_banner作为模型,然后调用复选框dashboard_banner[]。我认为这会导致错误。将它命名为d_banner[],然后在控制器中将ii命名为params[:d_banner]。然后你可以在控制器中循环或者做任何你喜欢的事情。
#1
2
I encountered the same error then I renamed the name of the checkbox array to something else other than the name of the model. It worked.
我遇到了相同的错误,然后将复选框数组的名称重命名为除模型名称之外的其他名称。它工作。
For example you have @dashboard_banners as your model then you call your checkbox dashboard_banners[]. I think that causes the error. Name it to something else like d_banner[] then fetch ii in the controller as params[:d_banner]. Then you can loop it in the controller or do anything that you like.
例如,您将@dashboard_banner作为模型,然后调用复选框dashboard_banner[]。我认为这会导致错误。将它命名为d_banner[],然后在控制器中将ii命名为params[:d_banner]。然后你可以在控制器中循环或者做任何你喜欢的事情。