我想从我的控制器或帮助器生成一个新链接。所以我不能使用视图中可用的link_to
方法。
我想通过指定控制器和操作来生成路径,而不是使用名称路径。例如:
{action: "index", controller: "accounts", id: "123"}
但是我将上述参数放入哪种方法?我还没有看过Path.new()
方法或类似的东西。
url_for :controller => 'accounts', :action => 'index', :id => 123
注意:在5.1
之前的Rails版本中,默认情况下url_helpers不包含在控制器中。所以你必须自己包括它:
include Rails.application.routes.url_helpers