2

I'm trying to implement Authlogic in Rails 3 and have just been having headache after headache...I'm extremely new to rails, so please forgive me for not being an expert. I followed the railscast on the subject which has been really helpful, but as soon as i submit my create new user form via the actual website I get this:

undefined method `activated?'

app/controllers/users_controller.rb:37:in `create'

Any help would be SO appreciated...had a headache with this tonight...

Code from create method:

  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = "Registration successful."
    else
      render :action => 'new'
    end
  end
Nakilon
  • 34,866
  • 14
  • 107
  • 142
Jamie
  • 1,004
  • 1
  • 14
  • 32
  • Paste the code in your `UsersController#create` method so we can see what it's trying to do. – Alex Wayne Feb 07 '11 at 22:58
  • 1
    If anyone else hits this issue - regenerate your user_session model and fill it with: class UserSession < Authlogic::Session::Base def to_key new_record? ? nil : [ self.send(self.class.primary_key) ] end end This fixed it for me...seems to be an error surrounding that model at the very least so take it back to basics! – Jamie Feb 07 '11 at 23:44
  • 2
    Jamie, please post this as an answer (you are even allowed to accept your own answer after two days). That way, this question doesn't come up as 'unanswered. Thanks. – jhwist Feb 08 '11 at 09:32

2 Answers2

5

If anyone else hits this issue - regenerate your user_session model and fill it with:

class UserSession < Authlogic::Session::Base 
  def to_key 
    new_record? ? nil : [ self.send(self.class.primary_key) ] 
  end 
end

This fixed it for me...seems to be an error surrounding that model at the very least so take it back to basics!

Jamie
  • 1,004
  • 1
  • 14
  • 32
  • This worked for me, but I was wondering how this fixes the issue and why? Thanks in advance if you can explain your answer :) – alvincrespo May 09 '11 at 21:51
  • Thanks, i had the same error on FactoryGirl.create(:user), and I was confused because I have `activated?` method in user model. – ole Mar 31 '13 at 19:52
2

The problem for me was the existence of a user_sessions table. If you created the UserSession model through a generator, you have a migration that creates that table.

Simply deleting the table (both in test and development databases) and the migration file solved the problem for me.

Cheers,

-- José

José Fernandes
  • 384
  • 2
  • 6