I have an existing code base that I am trying to upgrade from Rails 3.2 to Rails 4.0
I have a controller called assets_controller with the create method, and I have an entry in my routes file:
resources :assets
Using jQuery for ajax on the frontend, if I send a request to publish in the / assets browser, I get 405 (method not allowed):
$.ajax({method: 'POST', data: asset, url: '/assets' });
This worked well in Rails 3, and I can't figure out what the problem is.
Updates:
Here is 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 (ie 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
Here is the way out of 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
Here is my development log:
Started POST "/assets" for 127.0.0.1 at 2015-05-27 09:39:42 -0400
(yes, that's the whole magazine)
POST DATA: {"asset_type": "Document", "title": "DNS", "heading_id": 9999, "copyrightted": false, "url": " https: //confidental.url ", "pubtitle": "DNS", "author": ""}
Another edit: I commented out my entire route file for diagnostic purposes, here are the results of 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)
Are assets a kind of reserved endpoint on rails 4?