Can I name the Omniauth authentication routes?
I've added Omniauth to my rails 3.1 project and it all works fine. When I visit hostname/auth/facebook
I'm brought to a page where I can authorize access to my Facebook accou开发者_Python百科nt as you would expect.
I'm wondering if I can name that route though so that in my link_to
helpers I can write
<%= link_to 'Login with Facebook', facebook_login_path %>
instead of
<%= link_to 'Login with Facebook', '/auth/facebook' %>
Not a huge thing I know but I like the consistency.
Normally you would do something like this: In your routes.rb file:
get "auth/facebook", :to => "controller#action", :as => "facebook_login"
But in this case, the url that you are sent to isn't actually a URL part of your application - but the oauth url for Facebook. Therefore, you can't create a route for it.
The only thing you could do - like the commenter above pointed out - is to create a helper method in one of your helper files - like app/helpers/application_helper.rb
def facebook_login_path
"/auth/facebook"
end
精彩评论