ruby on rails 4 - How to pass the variables in model#create to model#show after redirection -
ruby on rails 4 - How to pass the variables in model#create to model#show after redirection -
i have photo_link variable want display in show.html
so click create in view, , brings me effects#create
def create @effect = effect.new(effect_params) @effect.save @pid = params[:effect][:pid] @photo_link = apply_effect1(@pid) respond_with(@effect) end
when check log, think redirect effects#show before display show.html
started post "/effects" 127.0.0.1 @ 2014-10-19 13:56:21 +1100 processing effectscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"zfqmgjkuqess+kqui1ewwl1t6beec9lzarrli8tkrcy=", "effect"=>{"effect1"=>"0", "effect2"=>"0", "effect3"=>"0", "pid"=>"37"}, "commit"=>"create effect"} unpermitted parameters: pid (0.1ms) begin transaction sql (0.4ms) insert "effects" ("created_at", "effect1", "effect2", "effect3", "updated_at") values (?, ?, ?, ?, ?) [["created_at", "2014-10-19 02:56:21.056844"], ["effect1", "f"], ["effect2", "f"], ["effect3", "f"], ["updated_at", "2014-10-19 02:56:21.056844"]] (1.0ms) commit transaction "37" post load (0.1ms) select "posts".* "posts" "posts"."id" = ? limit 1 [["id", 37]] redirected http://localhost:3000/effects/60 completed 302 found in 704ms (activerecord: 1.6ms) started "/effects/60" 127.0.0.1 @ 2014-10-19 13:56:21 +1100 processing effectscontroller#show html parameters: {"id"=>"60"} effect load (0.2ms) select "effects".* "effects" "effects"."id" = ? limit 1 [["id", 60]] rendered effects/show.html.erb within layouts/loginpage (0.6ms) user load (0.2ms) select "users".* "users" "users"."id" = 1 order "users"."id" asc limit 1 completed 200 ok in 391ms (views: 388.9ms | activerecord: 0.4ms)
and here effect#show
def show p "hihi im here" p params respond_with(@effect) end
is there anyway can pass @photo_link
show.html ??
respond_with
will, default, redirect show action. want customise location
param of respond_with
, redirected right place (in case, still show action, parameters). see http://apidock.com/rails/actioncontroller/mimeresponds/respond_with
i think it's like:
respond_with(@effect, location: effect_show_path(@effect, @photo_link))
ruby-on-rails-4
Comments
Post a Comment