Ruby On Rails Application.html.haml

时间:2010-11-25 00:27:57

标签: ruby-on-rails syntax haml hyperlink

我正在使用带有haml版本2.2.21的Ruby On Rails 2.3.5(在我的environment.rb文件中)我在视图中生成的所有链接(使用haml)最后添加了链接本身。

前:

%li 
    =link_to 'sign up', {:controller=> 'users' , :action=> 'signup'}

显示         注册(用户/注册)

任何人都知道为什么?

1 个答案:

答案 0 :(得分:0)

你应该能够做到:

=link_to 'Sign Up', user_registration_path

为了将来参考,您可以运行命令

rake routes

获取应用程序中所有命名路由的列表:

$ rake routes
      new_user_session GET    /users/sign_in(.:format)                                 {:action=>"new", :controller=>"devise/sessions"}
          user_session POST   /users/sign_in(.:format)                                 {:action=>"create", :controller=>"devise/sessions"}
  destroy_user_session GET    /users/sign_out(.:format)                                {:action=>"destroy", :controller=>"devise/sessions"}
         user_password POST   /users/password(.:format)                                {:action=>"create", :controller=>"devise/passwords"}
     new_user_password GET    /users/password/new(.:format)                            {:action=>"new", :controller=>"devise/passwords"}
    edit_user_password GET    /users/password/edit(.:format)                           {:action=>"edit", :controller=>"devise/passwords"}
         user_password PUT    /users/password(.:format)                                {:action=>"update", :controller=>"devise/passwords"}
     user_registration POST   /users(.:format)                                         {:action=>"create", :controller=>"devise/registrations"}
 new_user_registration GET    /users/sign_up(.:format)                                 {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET    /users/edit(.:format)                                    {:action=>"edit", :controller=>"devise/registrations"}
     user_registration PUT    /users(.:format)                                         {:action=>"update", :controller=>"devise/registrations"}
     user_registration DELETE /users(.:format)                                         {:action=>"destroy", :controller=>"devise/registrations"}

路由名称列在最左侧的列中。然后,您可以将“_path”附加到其中任何一个以访问该路径。