Rails custom routing for auto-login
I want to set up auto-login by giving the user a link/key they can use like http://domain.com/4yT67rw. The last 7 digits are random and assigned to the user model.
Is it possible to do this with custom routing? I imagine it would have to be something like a regex to detect that it is a key and not a model name or error.
Would be great if I could do something like:
map.connect 'reg_ex_here', :contro开发者_JAVA技巧ller => 'users', :action => 'key_redirect'
and then in the users controller:
def key_redirect
user = User.find_by_key(key)
redirect_to user_path(user)
end
Or probably some other easy way that I don't know about. ;)
Thanks
something like this should work for you:
map.key_redirect '/:key_id', :requirements => {:key_id => /regex_here/}, :controller => 'users', :actions => 'key_redirect'
As with all routes, you can then refer to key_redirect_path or key_redirect_url when constructing urls.
精彩评论