title: Routing error on production when saving in database (paperclip)
body: <p>I have an app that works fine in my development environment. On production it makes some routing errors when saving a new product or updating it.</p>
  
  <p>I'm using standard scaffolding and paperclip gem. As I said everything works pretty good on development.</p>
  
  <p>This is my controller code:</p>
  
  <pre><code>def create
    @product = Product.new(params[:product])
  
    respond_to do |format|
      if @product.save
        format.html { redirect_to products_path, :notice =&gt; 'El producto fue agregado CORRECTAMENTE.' }
        format.json { render :json =&gt; @product, :status =&gt; :created, :location =&gt; @product }
      else
        format.html { render :action =&gt; "new" }
        format.json { render :json =&gt; @product.errors, :status =&gt; :unprocessable_entity }
      end
    end
  end
  </code></pre>
  
  <p>When I create a new product in my development environment it redirects to show the new product with the id.</p>
  
  <pre><code>http://localhost:3000/admin/55
  </code></pre>
  
  <p>Thats the url in development when redirecting to the new product after it has been added.</p>
  
  <p>But on production:</p>
  
  <blockquote>
    <p><a href="http://www.tuwebenlaweb2.com.ar/admin/admin/55" rel="nofollow">http://www.tuwebenlaweb2.com.ar/admin/admin/55</a></p>
  </blockquote>
  
  <p>It changed the routes (there is an extra <code>admin</code> in the url) or something and it gives me this error in the production.log:</p>
  
  <pre><code>Started GET "/admin/admin/39" for 186.108.188.126 at Sun Aug 25 18:03:34 -0400 2013
  
  ActionController::RoutingError (No route matches [GET] "/admin/admin/39"):
    vendor/bundle/ruby/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  </code></pre>
  
  <p>This is my rake routes:</p>
  
  <pre><code>juako@juako:~/Dropbox/sexytoys$ rake routes
      products GET    /admin(.:format)          products#index
               POST   /admin(.:format)          products#create
   new_product GET    /admin/new(.:format)      products#new
  edit_product GET    /admin/:id/edit(.:format) products#edit
       product GET    /admin/:id(.:format)      products#show
               PUT    /admin/:id(.:format)      products#update
               DELETE /admin/:id(.:format)      products#destroy
          root        /                         sexytoys#inicio
      sexytoys GET    /sexytoys(.:format)       sexytoys#inicio
     productos GET    /productos(.:format)      sexytoys#productos
    categorias GET    /categorias(.:format)     products#categorias
       galeria GET    /galeria(.:format)        sexytoys#galeria
     primerIma GET    /primerIma(.:format)      sexytoys#primerIma
   add_to_cart GET    /add_to_cart(.:format)    sexytoys#add_to_cart
               POST   /add_to_cart(.:format)    sexytoys#add_to_cart
    empty_cart GET    /empty_cart(.:format)     sexytoys#empty_cart
               POST   /empty_cart(.:format)     sexytoys#empty_cart
     increment GET    /increment(.:format)      sexytoys#increment
               POST   /increment(.:format)      sexytoys#increment
     decrement GET    /decrement(.:format)      sexytoys#decrement
               POST   /decrement(.:format)      sexytoys#decrement
      checkout GET    /checkout(.:format)       sexytoys#checkout
               POST   /checkout(.:format)       sexytoys#checkout
         order GET    /order(.:format)          sexytoys#order
               POST   /order(.:format)          sexytoys#order
  </code></pre>
  
  <p>my routes.rb </p>
  
  <blockquote>
    <p>Sexytoys::Application.routes.draw do</p>
    
    <p>resources :products, :path => "admin"</p>
    
    <p>#resources :products   #resources :sexytoys   #match
    ':controller(/:action(/:id(.:format)))'</p>
    
    <p>root :to => 'sexytoys#inicio'</p>
    
    <p>get 'sexytoys' => 'sexytoys#inicio'   get 'productos' =>
    'sexytoys#productos'
         get 'categorias' => 'products#categorias'</p>
    
    <p>get 'galeria' => 'sexytoys#galeria'</p>
    
    <p>get 'primerIma' => 'sexytoys#primerIma'</p>
    
    <p>get 'add_to_cart' => 'sexytoys#add_to_cart'   post 'add_to_cart' =>
    'sexytoys#add_to_cart'</p>
    
    <p>get 'empty_cart' => 'sexytoys#empty_cart'   post 'empty_cart' =>
    'sexytoys#empty_cart'</p>
    
    <p>get 'increment' => 'sexytoys#increment'   post 'increment' =>
    'sexytoys#increment'</p>
    
    <p>get 'decrement' => 'sexytoys#decrement'   post 'decrement' =>
    'sexytoys#decrement'</p>
    
    <p>get 'checkout' => 'sexytoys#checkout'   post 'checkout' =>
    'sexytoys#checkout'</p>
    
    <p>get 'order' => 'sexytoys#order'   post 'order' => 'sexytoys#order'</p>
  </blockquote>
  
  <p>What could be causing this?</p>
  
  <p>Thanks
  Joaquin</p>
  
  <p>//////////</p>
  
  <p>my error in PRODUCTION.LOG</p>
  
  <p>thanks</p>
  
  <pre><code>Started GET "/admin/new" for 190.226.107.164 at Thu Aug 29 07:53:46 -0400 2013
  Processing by ProductsController#new as HTML
    Rendered products/_header.html.haml (3.9ms)
    Rendered products/_form.html.haml (12.2ms)
    Rendered products/new.html.haml (21.6ms)
  Completed 200 OK in 37ms (Views: 35.7ms | ActiveRecord: 0.0ms)
  
  
  Started POST "/admin/admin" for 190.226.107.164 at Thu Aug 29 07:53:50 -0400 2013
  Processing by ProductsController#create as HTML
    Parameters: {"commit"=&gt;"Guardar Cambios", "product"=&gt;{"precio"=&gt;"", "descripcion"=&gt;"dsfds", "pie"=&gt;"intro", "nombre"=&gt;"dfsdfs"}, "authenticity_token"=&gt;"MedLwu+JhiqOL6xKr0HS7zkCvBrkA54+EBeyPEZqTgo=", "utf8"=&gt;"✓"}
  [paperclip] Saving attachments.
  Redirected to http://www.tuwebenlaweb2.com.ar/admin/admin/41
  Completed 302 Found in 17ms (ActiveRecord: 10.7ms)
  
  
  Started GET "/admin/admin/41" for 190.226.107.164 at Thu Aug 29 07:53:50 -0400 2013
  
  ActionController::RoutingError (No route matches [GET] "/admin/admin/41"):
    vendor/bundle/ruby/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
    vendor/bundle/ruby/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/rack/logger.rb:26:in `call_app'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/rack/logger.rb:16:in `call'
    vendor/bundle/ruby/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/request_id.rb:22:in `call'
    vendor/bundle/ruby/1.8/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
    vendor/bundle/ruby/1.8/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
    vendor/bundle/ruby/1.8/gems/activesupport-3.2.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    vendor/bundle/ruby/1.8/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
    vendor/bundle/ruby/1.8/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
    vendor/bundle/ruby/1.8/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
    vendor/bundle/ruby/1.8/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
    vendor/bundle/ruby/1.8/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
    vendor/bundle/ruby/1.8/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/engine.rb:479:in `call'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/application.rb:220:in `call'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send'
    vendor/bundle/ruby/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
    passenger (3.0.18) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
    passenger (3.0.18) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
    passenger (3.0.18) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:171:in `send'
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:171:in `handle_spawn_application'
    passenger (3.0.18) lib/phusion_passenger/utils.rb:470:in `safe_fork'
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:180:in `start'
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rack_application'
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rack_application'
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
    passenger (3.0.18) helper-scripts/passenger-spawn-server:99
  </code></pre>