Monday 15 March 2010

sending data between actions within same controller using redirect_to method in rails 4.1 -



sending data between actions within same controller using redirect_to method in rails 4.1 -

class songscontroller < applicationcontroller def new @song = song.new end def create ids_collection = array.new # logic save multiple songs object , accumulate ids # in ids_collection variable. redirect_to new_song_url, notice: "songs saved" end end

i want followings points cleared or answered, hoping these sensible. 1. want pass ids_collection array 'new' method. 2. when pass (i.e. redirect_to new_song_url(ids_collection)) get, in url (i.e. "/songs/new.72%2f73") hard decode in new method. 3. want, 'ids_collection' key in params hash , values array in key. how can accomplish , need whitelist 'ids_collection' strong parameters ?

you have pass key, value pair new_song_url

redirect_to new_song_url(song_ids: ids_collection), notice: "songs saved"

then can access song_ids in new action follows,

params[:song_ids]

strong parameters deal mass assignment, not related trying do.

also note when access song_ids in new action, of type string. may want convert them integers, params[:song_ids].map(&:to_i)

ruby-on-rails

No comments:

Post a Comment