Question

Environment: VM with Ubuntu and latest versions of Rails and ruby installed

Application controller code:

class ApplicationController < ActionController::Base
  before_filter :set_current_user
  protected # prevents method from being invoked by a route
  def set_current_user
    debugger
    # we exploit the fact that find_by_id(nil) returns nil
    @current_user ||= Moviegoer.find_by_id(session[:user_id])
    redirect_to login_path and return unless @current_user
  end
end

used debugger @current_user is null as expected but the redirect statement is failing "No route match"

Routes.rb code:

get  'auth/:provider/callback' => 'sessions#create',:as => :login
post 'logout' => 'sessions#destroy'
get  'auth/failure' => 'sessions#failure'

The error:

Error: ActionController::RoutingError (No route matches {:controller=>"sessions", :action=>"create"}):
  app/controllers/application_controller.rb:8:in `set_current_user'
Was it helpful?

Solution

According to the routes specified,login_path expects an arguement, a value for 'provider' in auth/:provider/callback

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top