我在我的一个班级中使用重定向,但是对于发送回用户的URL有点困惑。
我的用户登录后,他的重定向如下:
redirect_to :controller => "mycontroller", :action => "myaction"
当我查看发回的网址时,我会看到以下内容:
http://l1vmgt08:8085/mycontroller/myaction/id
由于" id"在URL中,我还必须在我的路线中添加它,包括" id":
match "mycontroller/myaction/id", :to => "mycontroller#myaction", :via => :get
我不明白为什么重定向会添加" id"到URL。我想这是一个rails默认,但我不明白这个的好处在哪里。因为我只是想执行动作,所以我不需要id,也没有提供..
我想我错过了关于路由如何工作的关键点,但我没有找到解释这种行为的任何其他信息..
提前致谢:)
编辑:
这是登录操作:
def login_attempt
authorized_user = User.authenticate(params[:username_or_email],params[:login_password])
if authorized_user
session[:user_id] = authorized_user.id
redirect_to :controller => "webqipparser", :action => "parser_formular"
else
render "login"
end
端
答案 0 :(得分:0)
我的一位同事解决了这个问题。解决方案是不重定向到控制器/操作,而是重定向到路径,因为我只想渲染视图..
redirect_to controller_view_path