开发者

How Do I use redirect and pass an object to the edit action?

How Do I use redirect and pass an object to the edit action? The following code does not work:

  def edit
    @promotion = Promotion.find_by_id(@params['promo_id']) 
  end

  def update
    promotion = Promotion.find(params[:promotion_profile][:promotion_id])
       promo_perfil = promotion.profile

       if promo_perfil.update_attributes(params[:promotion_profile])

         redirect_to admin_edit_path(promotion.id => @params[:promo_id])
 开发者_StackOverflow社区      else
   end


The edit action is looking for params['promo_id'] (why @params['promo_id']?).

So pass :promo_id this way:

redirect_to admin_edit_path(:promo_id => promotion) 


You shouldn't redirect in this case just: render :action => :edit

This is standard Rails behaviour, you will see this in all scaffolded controllers as a way of re rendering the edit form with the current object in the update action without having to rely on stuffing objects into cookies to pass around.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜