В итоге я создал метод login_from_anonymous
в lib/authenticated_system.rb
, как показано ниже. Этот метод называется методом current_user, также показанным ниже.
def login_from_anonymous
user = User.new({"new_profile_attributes"=>
{ "country_code"=>"", "zip"=>"", "first_name"=>"Anonymous",
"last_name"=>"User", "affiliation_id"=>"1"
},
"password" => "anonymous123",
"password_confirmation" => "anonymous123",
#"invitation_token" => "",
"invitation_limit" => 0,
"login" => "anonymous_#{Time.now.strftime("%m-%d-%y+%I:%M:%S%p")}",
"email" => "anonymous@domain.org",
"current_ip" => request.env['REMOTE_ADDR']})
user.send(:create_without_callbacks)
self.current_user = user
handle_remember_cookie! true # freshen cookie token (keeping date)
self.current_user
end
def current_user
@current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || login_from_anonymous) unless @current_user == false
end