How can I get rails routes to match * for the final parameter of my url?

心已入冬 提交于 2019-12-12 02:29:47

问题


I would like to allow a user to automatically login if they use their encrypted password in the url. I have the following url that I would like matched with rails routes:

/attendants/update_player_status/game/1/maybe/user_hash/$2a$10$1kY8xvOjkqZJJJGWDd0q2Oeyl7kICSBDPTYzGhkJ6pZnE6YA/nJie

where the latter part of the url can have any characters, like * (ie. it can have '/' '$' '*' etc)

My routes works but then it bombs out on '/' in the parameter (as seen above):

match '/attendants/update_player_status/game/:game_id/:status/user_hash/:user_hash' => 'attendants#update_player_status_using_hash', :as => 'update_player_status_using_hash'

Any recommendations on what I should do? Once i pull the parameter correctly I will use it to login the user into the website, and allow very limited access.


回答1:


One option is route globbing (from the docs):

match 'photos/*other' => 'photos#unknown'

# In controller, params[:other] is everything after 'photos'

You could also use a regex in the match's constraints to allow a slash, as per this answer.

IMO the globbing is a bit more elegant; it may depend on the rest of your routes which is the best solution.



来源:https://stackoverflow.com/questions/8650336/how-can-i-get-rails-routes-to-match-for-the-final-parameter-of-my-url

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