Rails 4 Method Not Allowed after Upgrading from Rails 3
It turns out the problem was with the name 'assets' I can't find any documentation to confirm this, but renaming the asset model and controller to something else fixed the problem.
This isn't just about the word assets
. Rails does not like when a route path and the asset directory are in the same subdirectory.
When making a post request, you will get method not allowed
. The problem is there can be no overlap with paths and the asset directory. The problem is specifically with POST
requests in that path. I am assuming somewhere in rails, they must have disabled all non-GET requests for the assets directory.
In this very simple app below, you will get a method not allowed
error. Because the path /welcomes
is being used for a route and for an asset prefix.
File: config/environment/development.rb
config.assets.prefix = '/welcomes'
File: config/routes.rb
resources :welcomes, path: 'welcomes', only: ['index', 'create']
File: app/controllers/welcomes_controller.rb
class WelcomesController < ApplicationController def index @welcome = 'hello'; end def create @welcome = 'world'; endend
File: app/views/welcomes/index.html.rb
<%= form_for(@welcome) do |f| %> <%= f.submit 'Submit' %><% end %>
File: app/views/welcomes/create.html.rb
<h1>Welcomes#create</h1><p>Find me in app/views/welcomes/create.html.erb</p>
The issue is that your asset
controller routes are conflicting with the rails default /assets
path.
The simplest solution is to modify your config/routes.rb
file line to read as follows (or any other path of your choosing that is not assets
):
resources :assets, path: 'site_assets'