使用rails url helper,我将如何链接到home_controller.rb的联系人操作?
感谢清除它!
到目前为止,我的家庭控制器看起来像:
resources :home do
collection do
get 'about'
get 'contact'
end
end
答案 0 :(得分:1)
您正在寻找的变量是:
contact_home_index_url
和
contact_home_index_path
要查找这些(并查看所有其他路由),请在命令行中使用rake routes
。在右边,你会看到动作和控制器;找到您需要的行,获取左侧的变量,并根据需要将_path
或_url
附加到末尾。对于嵌套路由,您需要提供参数,例如:
new_event_boat_path(@event)
至于从控制器重定向,请尝试:
def redirect_sample
redirect_to contact_home_index_url
end