3

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?

SteenhouwerD
  • 1,819
  • 1
  • 16
  • 22
  • same problem here... did you find a workaround? – fro_oo Jun 24 '13 at 14:44
  • 1
    Seems to be similar to this question http://stackoverflow.com/questions/11445831/how-to-submit-multiple-new-items-via-rails-3-2-mass-assignment – MCB Jun 24 '13 at 18:19
  • The above link is quite useful and informative. It ultimately helped me overcome this problem. In addition, some well-known rubyists, including Avdi Grimm and Ryan Bates, give helpful answers and explanations. – Kurt Mueller Apr 29 '14 at 20:25

1 Answers1

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.

tungsten_carbide
  • 525
  • 5
  • 18