Reputation: 3345
How could I map this action
match '/auth/:provider/callback', to: 'sessions#create'
which gets called via
<b><%= link_to "Sign in with Facebook", "/auth/facebook", id: "sign_in" %></b>
to a path like login_path or to work with a subURI?
I have tried to: "sessions#create", as: "login" but this errors out with no routes matches for sessions#create. Thanks in advance!
Upvotes: 0
Views: 1038
Reputation: 33626
I believe you got confused a little.
This route you've talking about is the callback which the user is returned to after OmniAuth communicated with the 3rd-party service (eg. Facebook). So there's no point in naming this route using the :as
option (although you could).
What you want to edit (if I understood you) is the URL the user hits to Login so it doesn't look like http://example.com/auth/facebook but it looks like http://example.com/login.
It's just a static url (/auth/facebook) so you could just redirect it like this:
match "/login" => redirect("/auth/github")
If the URL that is visible to the user doesn't concern you but you just want to simplify it inside your views like:
<b><%= link_to "Sign in with Facebook", sign_in, id: "sign_in" %></b>
you could define this method in a helper (ApplicationHelper.rb for example):
def login_link
"/auth/facebook"
end
although I don't see any particular reason for doing this.
Upvotes: 1
Reputation: 10898
match '/auth/:provider/callback' => 'sessions#create'
The above routing code will help you, if you wan the /auth/twitter(:provider)/callback
to end in your SessionsController
=> create
action
Upvotes: 1