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

久未见 提交于 2019-12-25 02:25:41

问题


This is the route the Vanity gem generates:

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?


回答1:


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")


来源:https://stackoverflow.com/questions/7396104/with-the-route-generated-by-the-vanity-gem-what-is-the-rails-route-helper-i-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!