当我在开发中运行我的 Rails 3 Spree 应用程序并将图像上传到产品时,我得到以下信息:
Started POST "/admin/products/other-product/images" for 127.0.0.1 at Fri Apr 12 22:27:46 +1000 2013
Processing by Spree::Admin::ImagesController#create as HTML
Parameters: {"button"=>"", "image"=>{"viewable_id"=>"2", "alt"=>"", "attachment"=>#<ActionDispatch::Http::UploadedFile:0x7f6c16afbb38 @headers="Content-Disposition: form-data; name=\"image[attachment]\"; filename=\"minesweeper_example_alone_variables.png\"\r\nContent-Type: image/png\r\n", @original_filename="minesweeper_example_alone_variables.png", @tempfile=#<File:/tmp/RackMultipart20130412-28144-18934pd-0>, @content_type="image/png">}, "authenticity_token"=>"5sKQ4cysi+tUD4BMZlJIYhlnnQfWAqVoV65nckI8RAs=", "product_id"=>"other-product", "utf8"=>"✓"}
Spree::User Load (0.2ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."id" = 1 LIMIT 1
(0.1ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = 1 AND "spree_roles"."name" = 'admin'
Spree::Product Load (0.1ms) SELECT "spree_products".* FROM "spree_products" WHERE "spree_products"."permalink" = 'other-product' LIMIT 1
Spree::Variant Load (0.1ms) SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."product_id" = 2 AND "spree_variants"."deleted_at" IS NULL AND "spree_variants"."is_master" = 'f' ORDER BY "spree_variants".position ASC
Spree::Variant Load (0.1ms) SELECT "spree_variants".* FROM "spree_variants" WHERE "spree_variants"."product_id" = 2 AND "spree_variants"."is_master" = 't' LIMIT 1
Command :: identify -format %wx%h '/tmp/stream20130412-28144-bhw0tk-0.png[0]'
Command :: convert '/tmp/stream20130412-28144-bhw0tk-0.png[0]' -resize "48x48>" -strip -auto-orient '/tmp/stream20130412-28144-bhw0tk-020130412-28144-13nnruw-0'
Command :: identify -format %wx%h '/tmp/stream20130412-28144-bhw0tk-0.png[0]'
Command :: convert '/tmp/stream20130412-28144-bhw0tk-0.png[0]' -resize "600x600>" -strip -auto-orient '/tmp/stream20130412-28144-bhw0tk-020130412-28144-16xvtq9-0'
Command :: identify -format %wx%h '/tmp/stream20130412-28144-bhw0tk-0.png[0]'
Command :: convert '/tmp/stream20130412-28144-bhw0tk-0.png[0]' -resize "240x240>" -strip -auto-orient '/tmp/stream20130412-28144-bhw0tk-020130412-28144-nxogrs-0'
Command :: identify -format %wx%h '/tmp/stream20130412-28144-bhw0tk-0.png[0]'
Command :: convert '/tmp/stream20130412-28144-bhw0tk-0.png[0]' -resize "100x100>" -strip -auto-orient '/tmp/stream20130412-28144-bhw0tk-020130412-28144-1n2cil2-0'
Command :: identify -format %wx%h '/tmp/stream20130412-28144-bhw0tk-0.png[0]'
(0.1ms) begin transaction
Spree::Asset Load (0.2ms) SELECT "spree_assets".* FROM "spree_assets" WHERE ("spree_assets"."viewable_id" = 2) ORDER BY position DESC LIMIT 1
SQL (0.3ms) INSERT INTO "spree_assets" ("alt", "attachment_content_type", "attachment_file_name", "attachment_file_size", "attachment_height", "attachment_updated_at", "attachment_width", "position", "type", "viewable_id", "viewable_type") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["alt", ""], ["attachment_content_type", "image/png"], ["attachment_file_name", "minesweeper_example_alone_variables.png"], ["attachment_file_size", 7856], ["attachment_height", 271], ["attachment_updated_at", Fri, 12 Apr 2013 12:27:46 UTC +00:00], ["attachment_width", 110], ["position", 1], ["type", "Spree::Image"], ["viewable_id", 2], ["viewable_type", "Spree::Variant"]]
[paperclip] Saving attachments.
[paperclip] saving /home/robert/Code/Websites/sanair/public/spree/products/2/mini/minesweeper_example_alone_variables.png
[paperclip] saving /home/robert/Code/Websites/sanair/public/spree/products/2/large/minesweeper_example_alone_variables.png
[paperclip] saving /home/robert/Code/Websites/sanair/public/spree/products/2/product/minesweeper_example_alone_variables.png
[paperclip] saving /home/robert/Code/Websites/sanair/public/spree/products/2/small/minesweeper_example_alone_variables.png
[paperclip] saving /home/robert/Code/Websites/sanair/public/spree/products/2/original/minesweeper_example_alone_variables.png
(164.1ms) commit transaction
Redirected to http://localhost:3000/admin/products/other-product/images
Completed 302 Found in 545ms (ActiveRecord: 165.3ms)
但是每当我在生产中运行我的 Spree 应用程序并上传相同的图像时,我都会得到:
Started POST "/admin/products/total-microbe-test/images" for ###.###.###.### at Fri Apr 12 08:47:32 -0400 2013
ActionController::RoutingError (No route matches [POST] "/products/total-microbe-test/images"):
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `send'
railties (3.2.13) 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
所以看起来,在生产中,我的路线搞砸了。但是,我登录到生产服务器并运行:
bundle exec rake routes
我得到的其中一条是:
POST /admin/products/:product_id/images(.:format) spree/admin/images#create
所以现在我很困惑。路线应该在那里,但它的行为根本不像我期望的那样。
我究竟做错了什么?