Ruby on Rails Nested Forms - Unpermitted Parameters: users_attributes -


when trying add users band using nested_form gem, unable access users params. after investigation noticed getting unpermitted parameters error in console. need access users_attributes can search users in database display name in controller. (so nested_form add users in database, if there better way this, please let me know)

here error rails console:

started patch "/band_steps/videos" 127.0.0.1 @ 2015-04-29 01:59:03 -0400 processing bandstepscontroller#update html parameters: {"utf8"=>"✓", "authenticity_token"=>"oa16rrntw9tn/7n45jsjrg+q6vo8q+txryrhloksjys=", "band"=>{"users_attributes"=>{"0"=>{"display_name"=>"tyler", "_destroy"=>"false", "id"=>"330"}}}, "commit"=>"next", "id"=>"videos"} band load (0.2ms) select "bands".* "bands" "bands"."id" = $1 limit 1 [["id", 57]] unpermitted parameters: users_attributes (0.1ms) begin band exists (0.5ms) select 1 one "bands" (lower("bands"."name") = lower('asdfsbad') , "bands"."id" != 57) limit 1 (0.2ms) commit redirected http://localhost:3000/band_steps/music completed 302 found in 8ms (activerecord: 1.0ms)

the code form partial (_form.html.erb):

<%= nested_form_for @band, url: wizard_path |band_form| %>     <%= render partial: 'shared/error_messages', locals: {obj: band_form.object} %>     <%= yield band_form %>     <%= band_form.submit "next" %> <%end%> 

the code member.html.erb (the page calls partial)

<h3> add members band! </h3> <%= render layout: 'form' |band_form| %>     <%= band_form.fields_for :users |builder| %>         <%= render 'user_fields', builder:builder %>     <%end%>         <p><%= band_form.link_to_add "add member", :users %></p>     <br> <%end%> <%= link_to "skip step", next_wizard_path %><br> <%= link_to "back", previous_wizard_path %> 

the code _user_fields.html.erb (partial renders user fields)

<p> <%= builder.label :display_name, "display name" %> <%= builder.text_field :display_name %> <%= builder.link_to_remove "remove user" %> </p> 

relevant band controller code: (i'm posting methods directly involved save reading time, can post code needed)

create method:

def create     @band = band.new(band_params)     @band_params = band_params     if @band.save       session[:band_id] = @band.id       redirect_to band_steps_path     else       render :new     end  end 

the strong parameters:

def band_params

    params.require(:band).permit(:name, :location, :about_me, :profile_picture,    :full_address, :video_link, user_ids: [], genre_ids: [],    band_video_attributes: [:video_link, :video_name],     band_music_attributes: [:name, :embed_html],      genre_ids: [], users_attributes: []) end 

the band model:

has_many :user_bands, dependent: :destroy has_many :users, through: :user_bands accepts_nested_attributes_for :users, allow_destroy: true 

the user model:

has_many :user_bands has_many :bands, through: :user_bands 

to sum how code should work: band form has fields type in users' display names, access display names in bands controller.

i have spent quite bit of time looking through code see made mistake. appreciated.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -