Forum: Ruby on Rails routing issue, matching a param as action

Posted by Kad Kerforn (kadoudal)
on 2012-10-07 11:07
(Received via mailing list)
I have the following routes :

>>  match '/auth/:provider/callback', to: 'omniauth_callbacks#create'

I can test the :provider in the create action ..

is there any way to directly match to an action with the :provider
name ?
Posted by Kad Kerforn (kadoudal)
on 2012-10-07 17:15
(Received via mailing list)
It seems in some cases I can use the redirect

   match '/auth/:provider/callback', :to => redirect {|params| "/
omniauth_callbacks/#{params[:provider]}" }

but not in this case , as the redirect will change the request , and
I'll not be able to check for   request.env["omniauth.auth"]

so I resolved to write one match for each :provider .
  match '/auth/google_oauth2/callback', to:
'omniauth_callbacks#google_oauth2'
  match '/auth/facebook/callback', to: 'omniauth_callbacks#facebook'
  match '/auth/twitter/callback', to: 'omniauth_callbacks#twitter'
Posted by Ignacio Piantanida (Guest)
on 2012-10-07 22:25
(Received via mailing list)
You could do something like this:

match '/auth/:provider/callback', to: 'omniauth_callbacks#all_callbacks'

class OmniauthCallbacksController
  def all_callbacks
    send(params[:provider])
  end

  def facebook
    ....
  end

  def twitter
    ...
  end

  def method_missing(method_name, *args, &block)
    #do some stuff
  end
end

2012/10/7 Erwin <yves_dufour@mac.com>
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.