joh*_*ohn 19 action ruby-on-rails
我试图通过传递控制器,动作和参数来重定向rails以显示动作.但是,rails完全忽略了动作的名称!
我得到的是 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
Run Code Online (Sandbox Code Playgroud)
Sam*_*uel 35
为什么打架子?
redirect_to @tip
Run Code Online (Sandbox Code Playgroud)
您可以使用:notice选项缩短代码.
redirect_to @tip, :notice => 'Message here'
Run Code Online (Sandbox Code Playgroud)
如果是REST资源路由,则路由实际上是正确的.一个GET要求/tips/id实际调用的show动作.由于它的路由方式,我的猜测是你用它来路由它map.resources,这是正确的.
joh*_*ohn -3
这可能是暂时的“绕行”。使用渲染,效果非常好......
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39908 次 |
| 最近记录: |