简体   繁体   English

通过Vanity gem生成的路线,我可以使用什么Rails路线助手?

[英]With the route generated by the Vanity gem, what is the Rails route helper I can use?

This is the route the Vanity gem generates: 这是Vanity gem生成的路线:

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

This is the rake routes: 这是耙路:

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

How do I use the Rails link helper to link directly to URL mydomain.com/vname ? 如何使用Rails链接帮助程序直接链接到URL mydomain.com/vname

From the top of my head (sorry, I don't really have the time to test it right now): 从我的头顶上(抱歉,我现在没有时间进行测试):

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

which you would use like this: 您可以这样使用:

vanity_path(:vname => "marcamillion")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM