title: After save RuntimeError: Could not find a valid mapping for #<User id
body: <p>React app is making calls to ruby on rails api. I'm building signup page i got stuck on the signup save part. getting error</p>
  
  <pre><code>"status": 500,
  "error": "Internal Server Error",
  "exception": "#&lt;RuntimeError: Could not find a valid mapping for #&lt;User id: 7, email: \"bearatamer+testfive@gmail.com\", created_at: \"2019-06-19 05:35:58\", updated_at: \"2019-06-19 05:35:58\", fullname: \"test five\", provider: nil, uid: nil, image: nil, phone_number: \"6021233423\", description: nil, pin: nil, phone_verified: nil, stripe_id: nil, merchant_id: nil, unread: 0, access_token: \"JHqM4JiyjvdufcReQdYX\", is_commercial_host: false&gt;&gt;"
  </code></pre>
  
  <p>im sending this JSON </p>
  
  <pre><code>{"fullname": "test five", "phone_number": "6021233423",  "email": 
   "testuser+testfive@gmail.com",
  "is_commercial_host": "false",  "password": "test1234"
  }
  </code></pre>
  
  <p>to this api </p>
  
  <pre><code> http://localhost:3000/api/v1/signup
  </code></pre>
  
  <p>as you see on the below image 
  <a href="https://i.stack.imgur.com/nBWml.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nBWml.png" alt="enter image description here"></a></p>
  
  <p>this image is from the command line 
  <a href="https://i.stack.imgur.com/LEK2I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LEK2I.png" alt="enter image description here"></a></p>
  
  <p><strong>The record gets saved to the database but after it saves i get the error</strong></p>
  
  <p><a href="https://i.stack.imgur.com/2LeIt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2LeIt.png" alt="enter image description here"></a></p>
  
  <p>this is users_controller.rb</p>
  
  <pre><code>class Api::V1::UsersController &lt; ApplicationController
  before_action :authenticate_with_token!, only: [:logout]
  
  def facebook
   enter code hereif params[:facebook_access_token]
    graph = Koala::Facebook::API.new(params[:facebook_access_token])
    user_data = graph.get_object("me?fields=name,email,id,picture")
  
    user = User.find_by(email: user_data['email'])
    if user
      user.generate_authentication_token
      user.save
      render json: user, status: :ok
    else
      user = User.new(
                  fullname: user_data['fullname'],
                  email: user_data['email'],
                  uid: user_data['id'],
                  provider: 'Facebook',
                  image: user_data['picture']['data']['url']
              )
      user.generate_authentication_token
  
      if user.save
        render json: user, status: :ok
      else
        render json: { error: user.errors, is_success: false}, status: 422
      end
    end
    else
    render json: { error: "Invalid Facebook Token", is_success: false}, status: :unprocessable_entity
    end
  end
  
  def logout
   user = User.find_by(access_token: params[:access_token])
   user.generate_authentication_token
   user.save
   render json: { is_success: true}, status: :ok
  end
  
  def login
    user = User.find_by(email: params[:email]) 
      if user &amp;&amp; user.valid_password?(params[:password])
       session[:user_id] = user.id
       render json: user, status: :ok
      else
       render json: { error: user.errors, is_success: false}, status: 422
      end 
  end
  
  def signup
   user = User.find_by(email: params[:email]) 
   if user 
     render json: { error: "Email already exist, click on forget password", is_success: false}, status: :unprocessable_entity
   else
      user = User.new(
                  fullname: params[:fullname],
                  email: params[:email],
                  phone_number: params[:phone_number],
                  password:  params[:password],
                  is_commercial_host:  params[:is_commercial_host]
              )
      user.generate_authentication_token
      if user.save
        render json: user, status: :ok
      else
        render json: { success: "Email already exist, click on forget password", is_success: true}, status: :ok
      end
    end 
   end
  
  end
  </code></pre>
  
  <p>here is routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
  namespace :api, defautls: {format: :json} do
  namespace :v1 do
    get '/logout' =&gt; 'users#logout'
    get '/login' =&gt; 'users#login'
    post '/login' =&gt; 'users#login'
    post '/signup' =&gt; 'users#signup'
    end
   end
  end
  </code></pre>
  
  <p>here is user.rb model</p>
  
  <pre><code>class User &lt; ApplicationRecord
   has_secure_password
   before_create :generate_authentication_token
   devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, 
   :validatable,
       :confirmable, :omniauthable
   validates :fullname, presence: true, length: {maximum: 
   50}
  end
  def generate_authentication_token
   begin
    self.access_token = Devise.friendly_token
   end while self.class.exists?(access_token: access_token)
  end
  </code></pre>
  
  <p>The Error happens on line 64 of signup method on the users_controller.rb which is this line</p>
  
  <pre><code> if user.save
  </code></pre>