I have a SessionsHelper, which is where I define current_user:
module SessionsHelper
def current_user
@current_user ||= user_from_remember_token
end
.
.
.
private
def user_from_remember_token
User.authenticate_with_salt(*remember_token)
end
def remember_token
cookies.signed[:remember_token] || [nil, nil]
end
end
I have a UsersController that has a before_filter :authenticate. This authenticate is in SessionsHelper, and I am running into trouble here.
Rails handles all the cookies for me, but I built an API to use tokens for my mobile app, for which I have to send in params[:api_token] upon login and set the current_user.
I am thinking I have to do something like:
def current_user
@current_user ||=(user_from_remember_token || user_from_api_token)
end
but I am stuck because I am unsure if I can pass the params[:api_token] in the helper.
Can anyone point me in the right direction?
EDIT: I also have,
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
...
end
which allows me to use before_filter :authenticate from UsersController and access this method in SessionsHelper
If you include SessionsHelper in UsersController, the methods defined in SessionsHelper should have access to params.