0
votes

I am trying to make an app with Rails 4 & devise.

I am trying to follow this tutorial:

http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/

When I complete the steps, and run the server, I get this error

NoMethodError (undefined method `update' for nil:NilClass):
2015-12-14T20:37:03.180526+00:00 app[web.1]:   app/controllers/users_controller.rb:43:in `finish_signup'
2015-12-14T20:37:03.180540+00:00 app[web.1]: 

the finish sign up method is:

 def finish_signup
    # authorize! :update, @user 
    if request.patch? && params[:user] #&& params[:user][:email]
      if @user.update(user_params)
        @user.skip_reconfirmation!
        sign_in(@user, :bypass => true)
        redirect_to @user, notice: 'Your profile was successfully updated.'
      else
        @show_errors = true
      end
    end
  end

The specific line identified as the problem is:

  if @user.update(user_params)

Does anyone see what's going wrong? I don't know how to read the error to understand what it's complaining about. Can anyone see the problem?

1
You don't initialize @user variable. - Alexander Shlenchack
Hi, i"m really sorry, but not sure what you mean. Do you mean I should write @current_user instead? - Mel
Do you have before_action :set_filter, like in example? You should, otherwise there's no @user instance variable set. - Marek Lipka
Yes before_action :set_user, only: [:index, :show, :edit, :update, :destroy] - Mel
I should add :finish_signup, right? - Mel

1 Answers

0
votes

You are getting error, because your @user is nil.

What I can see from your comments is you need to update this

before_action :set_user, only: [:index, :show, :edit, :update, :destroy]

to this

before_action :set_user, only: [:index, :show, :edit, :update, :destroy, :finish_signup]