我试图通过传递controller、action和params来重定向rails以显示操作。然而,rails完全忽略了action的名称!
我得到的是http://mysite/controllername/paramId
所以我有错误信息....
下面是我使用的操作代码:
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]
if @tip.save
flash[:notice] = 'Tip was successfully updated.'
redirect_to :controller=>'tips', :action => 'show', :id => @tip.permalink
else
render :action => 'edit'
end
end 发布于 2010-06-12 06:40:03
这可能是一个暂时的“绕过”。使用render,它工作得非常好...
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发布于 2010-06-12 06:59:19
为什么要对抗框架呢?
redirect_to @tip您还可以使用:notice选项来缩短代码。
redirect_to @tip, :notice => 'Message here'发布于 2010-06-12 07:00:26
如果是REST资源路由,则路由实际上是正确的。/tips/id上的GET请求实际上调用了show操作。由于它的路由方式,我猜您是用map.resources路由它的,这是正确的。
https://stackoverflow.com/questions/3026394
复制相似问题