Ruby Devise, SessionsController.create, json - getting NameError: undefined 'build_resource'?

I'm new to the Ruby ecosystem and drowning. I guess I was spoiled by the easy intuition of Visual Studio w C #. Anyway, I'm using Ruby 1.9.3, Rails 3.2.13 and Devise 3.0.3 on Ubuntu. I can access this site through a browser on a PC. But when I try to do this from our Phonegap mobile application, I get this error:

NameError: 'undefined local variable or method' build_resource 'for # ..

Here is the code in session_controller.rb:

class SessionsController < Devise::SessionsController
  def create
    respond_to do |format|
      format.html {
        super
      }
      format.json {
        build_resource  # <-This line is evidently producing an error!
        user = User.find_for_database_authentication(:email => params[:user][:email])
        return invalid_login_attempt unless resource
        return invalid_login_attempt unless user
..

Obviously, this is the line containing build_resource that is generating the error. I would appreciate any help to tell me where to go. What does this line do? Is this a method call? How do you know what this means?

+1
1

, _controller.

build_resource, session_controller

  # Build a devise resource passing in the session. Useful to move
  # temporary session data to the newly created user.
  def build_resource(hash=nil)
    self.resource = resource_class.new_with_session(hash || {}, session)
  end

, ( , , ). , build_resource registrations_controller.

, , , create session_controller

super

, create session_controller, session_controller -

#devise/sessions_controller
def create
    self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_flashing_format?
    sign_in(resource_name, resource)
    yield resource if block_given?
    respond_with resource, location: after_sign_in_path_for(resource)
  end

gist , json api.

include

include Devise::Controllers::InternalHelpers

session_controller. , build_resource.

!

Edit

def create
    respond_to do |format|
    # when you log into the application through a web browser you go to the format.html option
    # Thus you're not calling the build_resource method
      format.html {
        super
      }
    # So, lets try to sign in without the build_resource 
    # I am not really sure what you can do, but try this
      format.json { 

        resource = User.find_for_database_authentication(:login=>params[:user_login][:login])
        return invalid_login_attempt unless resource

        if resource.valid_password?(params[:user_login][:password])
          sign_in("user", resource)
          render :json=> {:success=>true, :auth_token=>resource.authentication_token, :login=>resource.login, :email=>resource.email}
        return
        end
        invalid_login_attempt
      end
        # build_resource  # <-This line is evidently producing an error!
        # user = User.find_for_database_authentication(:email => params[:user][:email])
        # return invalid_login_attempt unless resource
        # return invalid_login_attempt unless user
+4

All Articles