I've got an existing codebase that I'm attempting to upgrade from Rails 3.2 to Rails 4.0
I have controller called assets_controller with a 'create' method and I have a an entry in my routes file:
resources :assets
Using jQuery for ajax on the front end, if I send a post request to '/assets' from a browser, I get 405 (Method Not Allowed):
$.ajax({method: 'POST', data: asset, url: '/assets' });
This worked just fine in Rails 3, and I can't seem to figure out what the issue is.
Updates:
Heres a simplified version of my controller:
class AssetsController < ApplicationController
skip_before_filter :verify_authenticity_token
def create
# params[:assets] is passed if a mass addition of assets (i.e. book) occurs
assets = []
if params[:assets]
assets = params[:assets]
else
assets.push params
end
last_asset_id = 0
assets.each do |asset_data|
asset = Object.const_get(asset_data[:asset_type]).new(asset_data)
if !asset.save
json_false_errors(asset.errors.full_messages)
return
else
last_asset_id = asset.id
end
end
end
end
Heres the output from 'rake routes'
assets GET /assets(.:format) assets#index
POST /assets(.:format) assets#create
new_asset GET /assets/new(.:format) assets#new
edit_asset GET /assets/:id/edit(.:format) assets#edit
asset GET /assets/:id(.:format) assets#show
PATCH /assets/:id(.:format) assets#update
PUT /assets/:id(.:format) assets#update
DELETE /assets/:id(.:format) assets#destroy
Heres my development log:
Started POST "/assets" for 127.0.0.1 at 2015-05-27 09:39:42 -0400
(yeah thats all the log has)
POST DATA: { "asset_type":"Document", "title":"DNS", "heading_id":9999, "copyrighted":false, "url":"https://confidental.url", "pubtitle":"DNS", "author":""}
Another Edit: I commented out my entire routes file for diagnostic purposes, these are the results of doing some manual testing:
POST http://localhost:8000/assets 405 (Method Not Allowed)
POST http://localhost:8000/asset 404 (Not Found)
POST http://localhost:8000/ass 404 (Not Found)
is assets some sort of reserved endpoint in rails 4?