【问题标题】:With the route generated by the Vanity gem, what is the Rails route helper I can use?通过 Vanity gem 生成的路由,我可以使用什么 Rails 路由助手?
【发布时间】:2011-09-13 02:12:44
【问题描述】:

这是Vanity gem 生成的路由:

controller :vanities do 
  match ':vname' => :show, :via => :get, :constraints => {:vname => /[A-Za-z0-9\-\+]+/}
end

这是 rake 路线:

GET    /:vname(.:format)                       {:vname=>/[A-Za-z0-9\-\+]+/, :controller=>"vanities", :action=>"show"}

如何使用 Rails 链接助手直接链接到 URL mydomain.com/vname

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 routing url-routing


    【解决方案1】:

    从头到尾(对不起,我现在真的没有时间测试它):

    controller :vanities do 
      match ':vname' => :show, :via => :get, :constraints => {:vname => /[A-Za-z0-9\-\+]+/}, :as => :vanity
    end
    

    你会这样使用:

    vanity_path(:vname => "marcamillion")
    

    【讨论】:

    • 老兄!!!你今晚着火了。非常感谢。这正是我所需要的。谢谢,谢谢,谢谢:)
    • 有趣的是,早上通常不是我的事 ;-)
    • 顺便说一句,消防员先生,这个怎么样:stackoverflow.com/questions/7394701/… :)
    猜你喜欢
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2013-09-28
    相关资源
    最近更新 更多