In my Rails app, I'm trying to use jQuery ajax to create a new item via the default create method in my controller.
My routes.rb looks like this:
resources :items
The server side code is still as it was generated:
# POST /items
# POST /items.json
def create
@item = Item.new(params[:item])
respond_to do |format|
if @item.save
format.html { redirect_to @item, :notice => 'Item was successfully created.' }
format.json { render :json => @item, :status => :created, :location => @item }
else
format.html { render :action => "new" }
format.json { render :json => @item.errors, :status => :unprocessable_entity }
end
end
end
And my JavaScript:
$("#capture_input").focusout(function() {
var description = $(this).val();
$.ajax({
type: "POST",
url: '/items/create.json',
data: {
item: {
description : description
}
},
dataType: 'json',
success: function(msg) {
alert( "Data Saved: " + msg );
}
});
});
This seems really straightforward, but I'm getting the following error:
ActionController::RoutingError (No route matches [POST] "/items/create.json"):
I've been able to use the default update method in a similar situation without any issues. What's the problem here?
EDIT: Fixed typo in routes.rb code.
rake routes? Do you see the route for items create with POST?