I am working on an application that has several areas which require user to be logged in to access. (I am using devise for logic).
I am currently using the following in my application controller to remember the target url (the link someone clicks on (that requires authentication)) such that it will take the user there after authenticating (as per How to direct user to a specific page after logging in with Devise and Rails) .
class ApplicationController < ActionController::Base
helper :content
protect_from_forgery
def after_sign_in_path_for(user)
origin_path = session[:origin_path]
default_redirect_path ="/"
clear_origin_path
if origin_path.present?
origin_path
else
params[:target].presence || default_redirect_path
end
end
private
def authenticate_user!
store_origin_path
super
end
def store_session
store_origin_path
end
def store_origin_path
session[:origin_path] = request.fullpath
end
def clear_origin_path
session[:origin_path] = nil
end
end
This all works great, but I have just noticed that when I try to access “/users/edit”, I am now given the error:
ArgumentError in Devise::RegistrationsController#edit
wrong number of arguments (1 for 0)
Rails.root: /home/james/*******
Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:19:in `authenticate_user!'
Request
Parameters:
None
Show session dump
_csrf_token: "XmrTSQOQ3Z0XTSn14LAX8LtMNVOwM4q3bQ+UhxjvgGM="
session_id: "2caaccc944774f2a7ac6f440c2f442d9"
user_return_to: "/my_tendersave"
warden.user.user.key: ["User", [1], "$2a$10$foTK/Em72/E0rILIuUv7su"]
warden.user.user.session: {"last_request_at"=>2013-01-25 01:48:43 UTC}
Show env dump
GATEWAY_INTERFACE: "CGI/1.2"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_CHARSET: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-GB,en-US;q=0.8,en;q=0.6"
REMOTE_ADDR: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
What can I do to ensure this works?
Do I need to change the application Controller?
Or override some other devise methods.
Thanks in advance for your help.
I simply renamed the method in application controller and called the correct superclass method.
ie.