Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested form parent object : got Rack::Utils::KeySpaceConstrainedParams

I'm making a banner system where I can upload a banner to a CampaignBanner ( with description, url and position ).

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

For example in my first fields_for I get in name for target_url :

dashboard_banners[21][target_url]

There I have my id but in the second fields for my banner I have :

dashboard_banners[][banner_attributes][data]

Here you can see that I don't have the number 21 anymore.

Is this linked to the internal server I got?

like image 730
SteenhouwerD Avatar asked Jun 19 '26 18:06

SteenhouwerD


1 Answers

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.

like image 174
tungsten_carbide Avatar answered Jun 23 '26 18:06

tungsten_carbide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!