New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model named "Asset" cannot accept PATCH or PUT requests #19996
Comments
Have you moved the asset pipeline to something other than |
No changes at all from default "scaffold" behavior. The only two routes were I have a current application in production for Spike TV with a model named Asset. It's running 4.1.8, but I'll be upgrading it soon, and so this test... I'm trying to add multiple-file uploads, and wanted to test a few different UX patterns before I rolled this into the main site. I've built systems with Asset as a model name in 2.3, 3.0, 3.1 (although that caused some pain -- had to disable the asset pipeline), 3.2 (no pain), 4.0 (no pain), and 4.1 (still no pain). My general experience with Rails over the years has been that reserved words are removed as we go forward, not returned to the field to battle again. |
I tried to reproduce this issue and created a sample app with scaffolding. https://github.com/prathamesh-sonpatki/asset-model-rails-app Having this issue for |
You wouldn't need to dig very far in the issue tracker to see complaints about Actually Reserved words appearing in each release -- though we do strive to minimize them. As far as I know, however, this is about the least reserved you can get: change one config setting, and the problem should go away: Rails.application.config.assets.prefix = '/the-other-assets' @prathamesh-sonpatki while you're there, are you able to confirm it works on 4.1? |
@matthewd Having same issue on 4.1 - https://github.com/prathamesh-sonpatki/asset-model-rails-app/tree/4-1 |
Here's a test app: https://github.com/walterdavis/asset-test |
Here's the relevant parts of the running Spike application: https://gist.github.com/walterdavis/3184e5eca1ffc2c3420c This app is in Rails 4.1, and I can post or put or patch assets all day long there. I have not made that change to the assets route as noted earlier (and that's a great tip, much easier than renaming my models!) |
@prathamesh-sonpatki thanks 👌 It looks like it's a sprockets 3-ism. Changing the Gemfile to use sprockets < 3 makes the message go away (though interestingly, it doesn't show a flash message after the save -- whereas it does when I change the assets route, on either sprockets version 😕). So, I'm closing this issue as not something we can fix in this repository; @walterdavis feel free to open an issue on sprockets if you feel strongly about this... but I suspect the best answer will be for you to change that config setting. Backwards compatibility notwithstanding, it seems reasonable (and less confusing) to me for sprockets to wholly own whichever route prefix it is assigned... if anything, I'd consider defending it more aggressively: fail as soon as you try to define any overlapping route. |
Thanks for the follow-up, and good to know there's a reasonable explanation. Besides changing that prefix with the preferences setting, do I also need to rename my assets folder? Or is this just a public path to the stable assets folder? |
@matthewd @walterdavis On digging more, this was added in Sprockets here - rails/sprockets@62847ac5 which is above Sprockets > 3.0. |
@walterdavis next time you do a precompile, a |
Thanks again. Just confirmed that myself, too. This makes me so much more comfortable then! |
Just ran into this about an hour ago. Changing the asset prefix worked. I'm glad I didn't hit this problem yesterday... this could have been a really long and painful debugging session. |
Hitting this issue as well. I don't think a GET /assets should return anything, except if there's an index.html file in there. And if you have an image called example and a resource called example in an assets namespace, it should load up the resource an only the image of you tack on say '.png' otherwise it should load the resource with .html, .xml, or .json |
What we be more ideal for me at least is if there was an opt in to not receiving Method Not Allowed. This would be helpful, but for individuals with not enough rails knowledge of what /assets does vs their /assets, it could be a bad idea. |
Look here: http://guides.rubyonrails.org/configuring.html#configuring-assets, specifically assets.prefix. Changing this to something other than assets should make this work without any issues. Walter On Aug 20, 2015, at 6:51 PM, Ben A. Morgan notifications@github.com wrote:
|
@walterdavis i think we're updating to |
Trying a new 4.2.1 application based on a working 4.1.8 application (entirely rebuilt in 4.2.1 using scaffold, not reusing any 4.1.8 code).
A model named Asset will work for a POST or GET request, but will not accept PATCH or PUT requests (did not test DELETE).
Testing in WEBrick, the browser shows a plain text error message
Method Not Allowed
. The console reportsStarted PATCH "/assets/1" for ::1 at 2015-05-02 15:32:49 -0400
and never proceeds beyond that point.Renaming Asset to Image (which is a misnomer for my application) allows everything to work as expected.
Also tested this on 4.2.0, so this seems to be the point of regression.
The text was updated successfully, but these errors were encountered: