I'm trying to build a RESTful API using ruby and its RESTful routes. I am completely new to ruby (this is my first project) and am finding it has a very steep learning curve. I have tried to generate a simple user model and am attempting to create a CRUD example with it. Currently I am stuck on creating the user object inside the controller from a posted json object. I have implemented my own create method and am trying to have it echo back the json object that I post to it. For some reason all I get is a 404 back and a page that shows my routs. Here is the model, controller, routes file and migration file that I used to implement the API, why doesn't it work as expected?
user model:
#the user model
class User < ActiveRecord::Base
validates :password, :email, :first_name, :last_name, :presence =>true
validates_uniqueness_of :email
end
db migration file:
#migration file
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :last_name, :null => false
t.string :email, :null => false
t.string :first_name, :null => false
t.string :password, :null => false
t.timestamps
end
end
end
Routes File:
Rails.application.routes.draw do
# Define api routes for user
namespace :api do
resources :user, :defaults => { :format => 'json' }
end
end
user controllers file:
#user controller
class UserController < ApplicationController
def create
puts params
end
end
What am I doing wrong? Why isn't my post object being displayed to the console?