Skip to content
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

Closed
walterdavis opened this issue May 3, 2015 · 17 comments
Closed

Model named "Asset" cannot accept PATCH or PUT requests #19996

walterdavis opened this issue May 3, 2015 · 17 comments

Comments

@walterdavis
Copy link

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 reports Started 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.

@matthewd
Copy link
Member

matthewd commented May 3, 2015

Have you moved the asset pipeline to something other than /assets? If you define application routes that overlap with config.assets.prefix, such misbehaviour would not surprise me. (Though I suppose the fact it used to work, might.)

@walterdavis
Copy link
Author

No changes at all from default "scaffold" behavior. The only two routes were resources :projects and resources :assets. No changes to asset pipeline at all, and I was running this in development, against MySQL. I had the same behavior in Thin as well as WEBrick.

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.

prathamesh-sonpatki added a commit to prathamesh-sonpatki/asset-model-rails-app that referenced this issue May 3, 2015
@prathamesh-sonpatki
Copy link
Member

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 POST action too. @walterdavis Please check if the app is right?

@matthewd
Copy link
Member

matthewd commented May 3, 2015

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?

@prathamesh-sonpatki
Copy link
Member

@walterdavis
Copy link
Author

Here's a test app: https://github.com/walterdavis/asset-test

@walterdavis
Copy link
Author

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!)

@matthewd
Copy link
Member

matthewd commented May 3, 2015

@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.

@matthewd matthewd closed this as completed May 3, 2015
@walterdavis
Copy link
Author

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?

@prathamesh-sonpatki
Copy link
Member

@matthewd @walterdavis On digging more, this was added in Sprockets here - rails/sprockets@62847ac5 which is above Sprockets > 3.0.

@matthewd
Copy link
Member

matthewd commented May 3, 2015

@walterdavis next time you do a precompile, a public/ subdirectory will be created with the new name; app/assets stays where it is. So yeah, as far as I know, that setting should be literally the only thing you need to change.

@walterdavis
Copy link
Author

Thanks again. Just confirmed that myself, too. This makes me so much more comfortable then!

@chrislambe
Copy link

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.

@BenMorganIO
Copy link
Contributor

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

@BenMorganIO
Copy link
Contributor

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.

@walterdavis
Copy link
Author

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:

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.


Reply to this email directly or view it on GitHub.

@BenMorganIO
Copy link
Contributor

@walterdavis i think we're updating to /assetz. Just some thoughts I thought I'd leave. I think there is a way to make the assets url not reserved though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants