2014-10-19 58 views
0

後,我有我要在show.html顯示PHOTO_LINK變量如何通過模型#變量創建模型#顯示重定向

所以我點擊視圖中創建,它使我效果#創建

def create 
    @effect = Effect.new(effect_params) 
    @effect.save 
    @pid = params[:effect][:pid] 
    @photo_link = apply_effect1(@pid) 
    respond_with(@effect) 
    end 

當我檢查日誌,我認爲這是重定向到效果#顯示顯示器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_link來show.html ??

回答

0

respond_with將在默認情況下將您重定向到show動作。你想要做的是自定義location參數respond_with,所以你會被重定向到正確的位置(在這種情況下,仍然是show動作,但帶有額外的參數)。見http://apidock.com/rails/ActionController/MimeResponds/respond_with

我認爲這是這樣的:

respond_with(@effect, location: effect_show_path(@effect, @photo_link))