我觉得这很简单,但我的头撞到墙上了。我试图告诉我的Rails应用程序,如果有一个参数(本例中的签名),我想重定向回家。这是我的密码:
<%= if @pc.signature.present? %><% redirect_to "pages#home" %><%end%>我经常遇到语法错误。顺便说一下,这是在edit.html.erb文件中。
发布于 2015-03-17 02:39:21
也许在你的控制器里你没有定义@pc?此外,使用路径而不是‘页面#主页’。它应该更像这样:
def edit
@pc = Pc.find(params[:id]) #or whatever your logic is
redirect_to root_path if @pc.signature.present?
# otherwise 'edit' template will be rendered
end发布于 2015-03-17 01:08:14
您需要在操作控制器上这样做,而不是在视图中。
def your_action
if @pc.signature.present?
redirect_to 'your_path_or_url'
end
endhttps://stackoverflow.com/questions/29089639
复制相似问题