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

Route Error in Heroku when performing Updates/Create #197

Closed
benjamintan opened this issue Jun 15, 2011 · 11 comments
Closed

Route Error in Heroku when performing Updates/Create #197

benjamintan opened this issue Jun 15, 2011 · 11 comments
Labels

Comments

@benjamintan
Copy link

First off, thank you for a wonderful plugin!

I encountered a weird issue, and a possible workaround, hopefully it would help some one out there.

On localhost, I've installed ActiveAdmin views to a "Badges" model, where I can upload pictures (via paperclip) of the badge, along with all the other CRUD actions.

CRUD works fine on localhost, however, once I deploy to Heroku, weird things happen:

(1) On first deploy, creating a new Badge would work, but editing/updating would fail. Looking at heroku logs, it shows a routing error at that /admin/badge/8. So I tried heroku restart

(2) Now, editing/updating works, but creating a new badge would fail, where its complaining that /admin/badges cannot be found.

So after fiddling around, I've just settled on including these in the routes.rb

get '/admin/badges/:id' => 'admin/badges#show'
match '/admin/badges/:id' => 'admin/badges#update'
match '/admin/badges' => 'admin/badges#create'
get '/admin/badges/new' => 'admin/badges#update'

And so far so good. Maybe ActiveAdmin.routes(self) has some issues with Heroku (or the other way round)? Either way, prior to this, "rake routes" works fine.

Any better suggestions?

@TheKidCoder
Copy link
Contributor

I have seen this intermittent issue aswell on my Ubuntu VPS. I too was using paperclip and couldn’t find a solution. Sometimes updates would work, sometimes they wouldn’t....

I switched from paperclip to CarrierWave (which kicks the pants off of paperclip, btw) and the problem has seemed to stop. Give that a shot.

@rsalles
Copy link

rsalles commented Jun 23, 2011

Same issue for me. I use paperclip too.

@rsalles
Copy link

rsalles commented Jun 24, 2011

Have you tried to use the production environment on your localhost? For me, it doesn't work (whereas it works for dev).
So maybe we have to search there...

@timriley
Copy link

+1 on this issue. Have been experiencing it on models that use dragonfly for image uploads.

@benjamintanweihao
Copy link

Strange, then it seems like its not only happening to paperclip. So how did you get around this problem?

@timriley
Copy link

For now, I put in place some manual routes like the ones in the original bug report.

@rsalles
Copy link

rsalles commented Jun 27, 2011

In fact, it's related to multipart forms and PUT requests. They are transformed in POST: that s why your solution works timriley (btw, thx for it ;).

I have also noticed that in dev environment, it works whereas in prod it doesn't. Indeed, it s this line (in config/environments/production.rb): "config.cache_classes = true/false" which change the behavior.

I think we have to find a solution for that: a first hack should be to transform the PUT requests in POST. But I don't like this solution...

Any other idea?

@stungeye
Copy link

I am also experiencing this issue on an Ubuntu VPS. The routing errors only occur in production mode with admin forms that make use of a file upload input (for Paperclip).

I added the following routes to get things working again for a 'party' model:

post '/admin/parties/:id' => 'admin/parties#update'
get '/admin/parties/:id'   => 'admin/parties#show'
put '/admin/parties' => 'admin/parties#create'

@powow
Copy link

powow commented Jul 21, 2011

The real problem seems to be that the form_config is being cached if :multipart is true.

This means that if you restart the app and load the edit view then :method will always be "put",
and if you load the new view first, then the :method will always be non-existing.

But why does it cache the :method when multipart is set? And where?

@rolfb
Copy link
Contributor

rolfb commented Jul 21, 2011

I posted as powow earlier, sorry.

This error relates to any custom :html options in the form setup, not just :multipart => true, and not just Heroku.

Found that it's actually the form_config[:html] object which is cached and subsequently modified by formtastic. It can be duped right before the call to semantic_form_for in /lib/active_admin/view_helpers/form_helper.rb to fix, but personally I find that to be a bit dirty, would love to have another solution.

Also wondering how to test an error which only happens in production (when config.cache_classes is set).

gregbell added a commit that referenced this issue Jul 26, 2011
whatthewhat pushed a commit to whatthewhat/active_admin that referenced this issue Aug 13, 2011
@pcreux
Copy link
Contributor

pcreux commented Sep 28, 2011

Looks like this is fixed! :)

@pcreux pcreux closed this as completed Sep 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants