我如何链接到我的home_controller.rb的联系人操作?

时间:2010-12-07 03:17:08

标签: ruby-on-rails

使用rails url helper,我将如何链接到home_controller.rb的联系人操作?

  1. 如何生成链接
  2. 如何获得路径?
  3. 如何在动作中重定向?
  4. 感谢清除它!

    到目前为止,我的家庭控制器看起来像:

    resources :home do
        collection do
          get 'about'
          get 'contact'
        end
      end
    

1 个答案:

答案 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