开发者

Rails: redirect_to :controller=>'tips', :action => 'show', :id => @tip.permalink

I tried to redirect rails to show action by passing controller, action, and params. However, rails ignores the name of action totally!

what I got is http://mysite/controllername/paramId

so i have error message....

here is the action code I used:

def update
    @tip = current_user.tips.find(params[:id])
    @tip.attributes = params[:tip]
    @tip.category_ids = params[:categories]
    @tip.tag_with(params[:tags]) if params[:tags]


  开发者_如何学JAVA  if @tip.save
      flash[:notice] = 'Tip was successfully updated.'
      redirect_to :controller=>'tips', :action => 'show', :id => @tip.permalink
    else
      render :action => 'edit'
    end
  end 


Why fight the framework?

redirect_to @tip

And you can shorten your code by using the :notice option.

redirect_to @tip, :notice => 'Message here'


If its a REST resource route, the routing is actually correct. A GET request on /tips/id actually calls the show action. Because of the way it is routing, my guess is that you routed it with map.resources, and this is correct.


This might be a temporary "get around". Using render, it works very well....

if @tip.save
  flash[:notice] = 'Tip was successfully updated.'
   render :action => 'show', :id => @tip.permalink
 # redirect_to :controller=>'tips', :action => 'show', :id => @tip.permalink
else
  render :action => 'edit'
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜