title: How to save rails object from a JSON POST?
body: <p>I would like to know how to save an object in rails 3 via a JSON POST? </p>
  
  <p>The issue is that <strong>UsersController.rb</strong> doesn't recognize the <strong>JSON POST</strong> parameters and assumes there are no parameters in the request.</p>
  
  <p>I have two create methods that do the same, just to debug the issue. Thanks in advance!</p>
  
  <p><strong>Routes.rb</strong></p>
  
  <pre><code>post 'users'          =&gt; "users#create"
  match 'users/create'  =&gt; "users#create_user", :via =&gt; [ :post]
  </code></pre>
  
  <p><strong>User.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :token_authenticatable, :confirmable,
    # :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable,
           :validatable, :token_authenticatable #, :omniauthable
  
    has_many :leader_boards
  
    # Setup accessible (or protected) attributes for your model
    attr_accessible :email, :password, :password_confirmation, :remember_me, :authentication_token , :first_name, :large_profile_image_url, :last_name, :profile_image_url, :provider, :uid
  
    validates :email, :uniqueness =&gt; { :case_sensitive =&gt; false }
    validates :email, :first_name, :last_name, :presence =&gt; true
    validates :password, :password_confirmation, :presence =&gt; true
    validates :password, :length =&gt; { :minimum =&gt; 8 }
  
    def name
      return self.first_name.to_s + ' ' + self.last_name.to_s
    end
  end
  </code></pre>
  
  <p><strong>UsersController.rb</strong></p>
  
  <pre><code>module Api
    module V1
      class UsersController &lt; ApplicationController
        before_filter :authenticate_user!, :except =&gt; [:create, :show, :update, :create_user, :facebook,:leader_board]
        respond_to :json
  
        def create
          @user = User.create(params[:user])
          begin
            @user.reset_authentication_token!
          rescue
  
          end
          respond_with @user
        end
  
        def create_user
          begin
            @user = User.new
            @user.email = params[:email]
            @user.password  = params[:password]
            @user.password_confirmation   = params[:password_confirmation]
            @user.first_name = params[:first_name]
            @user.last_name  = params[:last_name]
            @user.save
          rescue
  
          end
          respond_with @user
        end
  </code></pre>
  
  <p><strong>JSON POST</strong></p>
  
  <blockquote>
    <p>{ "email": "jordanpass@jordanpass.cpm", "first_name": "mike", "last_name": "jordan",
    "password": "jordanpass", "password_confirmation": "jordanpass" }</p>
  </blockquote>
  
  <p><strong>Response</strong></p>
  
  <pre><code>{"errors":{"email":["can't be blank","can't be blank"],"password":["can't be blank","can't be blank","is too short (minimum is 8 characters)"],"first_name":["can't be blank"],"last_name":["can't be blank"],"password_confirmation":["can't be blank"]}}
  </code></pre>
  
  <p><strong>Sample Post Alternative Screenshot</strong></p>
  
  <p><a href="https://i.stack.imgur.com/u78iu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u78iu.png" alt=""></a></p>