gpt4 book ai didi

ruby-on-rails - rails : redirect_to :controller= >'tips' , :action => 'show' , :id => @tip. 永久链接

转载 作者:行者123 更新时间:2023-12-03 12:31:13 26 4
gpt4 key购买 nike

我试图通过传递 Controller 、 Action 和参数来重定向 Rails 以显示 Action 。但是,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

最佳答案

为什么要对抗框架?

redirect_to @tip

你可以使用 :notice 选项来缩短你的代码。
redirect_to @tip, :notice => 'Message here'

关于ruby-on-rails - rails : redirect_to :controller= >'tips' , :action => 'show' , :id => @tip. 永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3026394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com