Ruby on rails 4 重定向后如何将modelcreate中的变量传递给modelshow
我想在show.html中显示一个photo_link变量 因此,我在视图中单击“创建”,它将带我进入effectscreateRuby on rails 4 重定向后如何将modelcreate中的变量传递给modelshow,ruby-on-rails-4,Ruby On Rails 4,我想在show.html中显示一个photo_link变量 因此,我在视图中单击“创建”,它将带我进入effectscreate def create @effect = Effect.new(effect_params) @effect.save @pid = params[:effect][:pid] @photo_link = apply_effect1(@pid) respond_with(@effect) end 当我检查日志时,我认为
def create
@effect = Effect.new(effect_params)
@effect.save
@pid = params[:effect][:pid]
@photo_link = apply_effect1(@pid)
respond_with(@effect)
end
当我检查日志时,我认为它被重定向到effectsshow,然后再显示到show.html
Started POST "/effects" for 127.0.0.1 at 2014-10-19 13:56:21 +1100
Processing by EffectsController#create as 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 INTO "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".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", 37]]
Redirected to http://localhost:3000/effects/60
Completed 302 Found in 704ms (ActiveRecord: 1.6ms)
Started GET "/effects/60" for 127.0.0.1 at 2014-10-19 13:56:21 +1100
Processing by EffectsController#show as HTML
Parameters: {"id"=>"60"}
Effect Load (0.2ms) SELECT "effects".* FROM "effects" WHERE "effects"."id" = ? LIMIT 1 [["id", 60]]
Rendered effects/show.html.erb within layouts/loginpage (0.6ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Completed 200 OK in 391ms (Views: 388.9ms | ActiveRecord: 0.4ms)
这是我的表演
def show
p "HIHI IM HERE"
p params
respond_with(@effect)
end
我是否可以将@photo_链接传递到show.html 默认情况下,用will回复,将您重定向到show动作。您要做的是自定义respond_with的location参数,因此在本例中,您将被重定向到正确的位置,仍然是show操作,但带有额外的参数。看
我认为它是这样的:
respond_with(@effect, location: effect_show_path(@effect, @photo_link))