我正在构建一些 Rails 示例应用程序,其中我有两个模型用户和项目。两者之间的关联是用户 has_many 项目。现在的问题是,我愿意在顶部为用户的项目提供一些下拉菜单,如果有人单击该下拉菜单,它将把它带到项目显示页面。但是,如果用户在一个项目的编辑页面并从下拉列表中选择其他项目,我希望他到达新选定项目的编辑页面,同样的情况下显示页面的任何想法。我正在寻找的解决方案是例如:- 我们可以使用 params[:controller] 找到当前 Controller ,使用 params[:action] 找到当前 Action 我怎样才能找到当前路线。 提前致谢
如果有人想查看我的代码:- 这里是 github 的链接:- ' https://github.com/peeyushsingla/session_test.git/在这里我使用简单的链接,但实际上我会提供一些将显示的单个下拉列表,它将适用于所有编辑、显示、新的每个操作
最佳答案
对于 Rails 4
URL 示例:http://localhost:3000/allreferred?&referred_name=maria
request.path -> "/allreferred"
request.base_url -> "http://localhost:3000"
request.fullpath -> "/allreferred?&referred_name=maria"
request.original_url -> "http://localhost:3000/allreferred?&referred_name=maria"
关于ruby-on-rails - 如何在rails中获取当前路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20181216/