2015-09-27 92 views
1

我正在使用TinyMCE Imageupload在rails上工作。Rails。 TinyMCE ImageUpload正在請求GET而不是開發中的POST POST

它在開發中工作得很好(足夠有趣,它曾用於生產)。問題是,對生產它發出了錯誤的GET請求:

ActionController::RoutingError (No route matches [GET] "/at/tinymce_assets"): 

兩個問題在這裏:首先 - 它把一個區域設置在前面,其次它採用了GET請求。

在發展但它工作得很好:

Started POST "/tinymce_assets" for 127.0.0.1 at 2015-09-27 02:33:10 +0200 
Processing by TinymceAssetsController#create as HTML 

我的routes.rb看起來是這樣的:

Rails.application.routes.draw do 

    root to: 'static_pages#redirect' 

    localized do 

    match '', to: 'static_pages#welcome', :as => 'welcome', via: 'get' 

    ... lots of other stuff ... 

    end 

    match '*path', to: redirect("/#{I18n.locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }, via: 'get' 
    post '/tinymce_assets/' => 'tinymce_assets#create', :trailing_slash => false 
end 

我在這裏加入:trailing_slash =>假的 - 因爲它被設置爲true在environment.rb中

問:

爲什麼生產站點決定啓動一個GET請求+添加語言環境,但是開發會做它應該做的一切事情?我在哪裏可以設置此行爲?

更新 - 增加附加信息

把我上面的局部部分的文章中,我仍然得到同樣的錯誤後 - 這裏的全部跟蹤:

I, [2015-09-28T16:32:07.614317 #6136] INFO -- : Started GET "/tinymce_assets/" for 82.84.80.128 at 2015-09-28 16:32:07 -0400 
I, [2015-09-28T16:32:07.722280 #6136] INFO -- : Started GET "/at/tinymce_assets/" for 82.84.80.128 at 2015-09-28 16:32:07 -0400 
F, [2015-09-28T16:32:07.726369 #6136] FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/at/tinymce_assets"): 
    actionpack (4.1.12) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    actionpack (4.1.12) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.1.12) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.1.12) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.1.12) lib/rails/rack/logger.rb:20:in `call' 
    request_store (1.2.0) lib/request_store/middleware.rb:8:in `call' 
    actionpack (4.1.12) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.5.5) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.5.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (4.1.12) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call' 
    rack (1.5.5) lib/rack/sendfile.rb:112:in `call' 
    railties (4.1.12) lib/rails/engine.rb:514:in `call' 
    railties (4.1.12) lib/rails/application.rb:144:in `call' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception' 

如果我添加uploadimage_form_url:「/ tinymce_assets 「(同樣是帖子在上面)同樣的情況發生,除了它現在正在尋找本地化版本:

ActionController::RoutingError (No route matches [GET] "/at/tinymce_assets"): 
    actionpack (4.1.12) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    actionpack (4.1.12) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.1.12) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.1.12) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.1.12) lib/rails/rack/logger.rb:20:in `call' 
    request_store (1.2.0) lib/request_store/middleware.rb:8:in `call' 
    actionpack (4.1.12) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.5.5) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.5.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (4.1.12) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call' 
    rack (1.5.5) lib/rack/sendfile.rb:112:in `call' 
    railties (4.1.12) lib/rails/engine.rb:514:in `call' 
    railties (4.1.12) lib/rails/application.rb:144:in `call' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads' 
    /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception' 

整個安裝工作​​在我的本地環境:

tinymce-rails (4.2.5) 
tinymce-rails-imageupload (4.0.16.beta, 3.5.6.4) 

OSX Yosemite 10.10.5 
Rails 4.1.12 
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0] 

曾經工作過的設置,但不anylonger(無明顯變化之後 - 雖然我目前還打算通過我的Git修訂):

tinymce-rails (4.2.5) 
tinymce-rails-imageupload (4.0.16.beta, 3.5.8.3) 
Ubuntu 14.04.2 LTS 
Rails 4.1.12 
ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux] 

在這裏,在該申請中使用的寶石的完整列表:

*** LOCAL GEMS *** 

actionmailer (4.1.12) 
actionpack (4.1.12) 
actionview (4.1.12) 
activemodel (4.1.12) 
activerecord (4.1.12) 
activesupport (4.1.12) 
addressable (2.3.8) 
arel (5.0.1.20140414130214) 
bcrypt (3.1.10) 
better_errors (2.1.1) 
bigdecimal (1.2.4) 
binding_of_caller (0.7.2) 
bootstrap-datepicker-rails (1.4.0) 
bootstrap-sass (3.1.1.1) 
bootstrap-timepicker-rails (0.1.3) 
bootstrap_form (2.3.0) 
breadcrumbs_on_rails (2.3.1) 
browser (1.0.1) 
builder (3.2.2) 
bundler (1.10.5) 
cancancan (1.12.0) 
capistrano (3.1.0) 
capybara (2.5.0) 
carrierwave (0.10.0) 
chart-js-rails (0.0.8) 
childprocess (0.5.6) 
chronic (0.10.2) 
climate_control (0.0.3) 
cocaine (0.5.7) 
cocoon (1.2.6) 
coderay (1.1.0) 
coffee-rails (4.0.1) 
coffee-script (2.4.1) 
coffee-script-source (1.9.1.1) 
colorize (0.7.7) 
config (1.0.0) 
css_splitter (0.4.2) 
database_cleaner (1.5.0) 
debug_inspector (0.0.2) 
deep_merge (1.0.1) 
dependent-fields-rails (0.4.2) 
devise (3.5.2) 
diff-lcs (1.2.5) 
domain_name (0.5.24) 
dragonfly (0.9.15) 
dropzonejs-rails (0.7.1) 
erubis (2.7.0) 
escape_utils (1.1.0) 
execjs (2.6.0) 
factory_girl (4.2.0) 
factory_girl_rails (4.2.1) 
faker (1.5.0) 
fast_blank (1.0.0) 
fast_stack (0.1.0) 
ffi (1.9.10) 
flamegraph (0.1.0) 
font-awesome-rails (4.2.0.0) 
friendly_id (5.1.0) 
friendly_id-globalize (1.0.0.alpha2) 
gaffe (1.0.2) 
geocoder (1.2.10) 
gli (2.13.2) 
globalize (4.0.3) 
globalize-accessors (0.1.5) 
gmaps4rails (2.1.2) 
gritter (1.1.0) 
haml (4.0.7) 
haml-rails (0.9.0) 
html2haml (2.0.0) 
http-cookie (1.0.2) 
i18n (0.6.11) 
io-console (0.4.3) 
jbuilder (1.5.3) 
jquery-fileupload-rails (0.4.5) 
jquery-rails (3.1.4) 
jquery-ui-rails (5.0.5) 
json (1.8.3, 1.8.1) 
launchy (2.4.3) 
lazyload-rails (0.3.1) 
libv8 (3.16.14.11 x86_64-linux) 
localeapp (0.9.3) 
mail (2.6.3) 
mail_form (1.5.1) 
maxminddb (0.1.8) 
mime-types (2.6.1) 
mimemagic (0.3.0) 
mini_portile (0.6.2) 
minitest (5.8.0, 4.7.5) 
mobileesp_converted (0.2.3) 
mobvious (0.3.2) 
mobvious-rails (0.1.2) 
modernizr-rails (2.7.1) 
multi_json (1.11.2) 
mysql2 (0.3.20) 
net-scp (1.2.1) 
net-ssh (2.9.2) 
netrc (0.10.3) 
nokogiri (1.6.6.2) 
orm_adapter (0.5.0) 
paper_trail (4.0.0) 
paperclip (4.3.0) 
papercrop (0.2.0) 
pr_geohash (1.0.0) 
psych (2.0.5) 
pundit (1.0.1) 
quiet_assets (1.1.0) 
rack (1.5.5) 
rack-cache (1.2) 
rack-mini-profiler (0.9.7) 
rack-test (0.6.3) 
rails (4.1.12) 
rails4-autocomplete (1.1.1) 
rails_layout (1.0.26) 
railties (4.1.12) 
rake (10.4.2, 10.1.0) 
rake-compiler (0.9.5) 
rdoc (4.2.0, 4.1.0) 
recaptcha (0.4.0) 
redis (3.2.1) 
redis-actionpack (4.0.1) 
redis-activesupport (4.1.1) 
redis-namespace (1.5.2) 
redis-rack (1.5.0) 
redis-rack-cache (1.2.2) 
redis-rails (4.0.0) 
redis-store (1.1.6) 
ref (2.0.0) 
request_store (1.2.0) 
responders (1.1.2) 
rest-client (1.8.0) 
role_model (0.8.2) 
route_downcaser (1.1.4) 
route_translator (4.0.0) 
rsolr (1.0.12) 
rspec-core (2.14.8) 
rspec-expectations (2.14.5) 
rspec-mocks (2.14.6) 
rspec-rails (2.14.2) 
ruby_parser (3.7.1) 
rubyzip (1.1.7) 
sass (3.4.18) 
sass-rails (5.0.4) 
sdoc (0.4.1) 
seed_dump (3.2.2) 
selenium-webdriver (2.47.1) 
settingslogic (2.0.9) 
sexp_processor (4.6.0) 
sitemap_generator (5.1.0) 
sprockets (3.3.4) 
sprockets-rails (2.3.3) 
sshkit (1.7.1) 
sunspot (2.2.0) 
sunspot_rails (2.2.0) 
sunspot_solr (2.2.0) 
test-unit (2.1.6.0) 
therubyracer (0.12.1) 
thor (0.19.1) 
thread_safe (0.3.5) 
tilt (2.0.1) 
tinymce-rails (4.2.5) 
tinymce-rails-imageupload (4.0.16.beta, 3.5.8.3) 
tzinfo (1.2.2) 
uglifier (2.7.2) 
underscore-rails (1.8.3) 
unf (0.1.4) 
unf_ext (0.0.7.1) 
videojs_rails (4.12.14) 
warden (1.2.3) 
websocket (1.2.2) 
whenever (0.9.4) 
wiselinks (1.2.1) 
xpath (2.0.0) 
ya2yaml (0.31) 

希望這有助於光棚進入的情況。 :)

回答

1

您應該交換最後的match '*path'行和post '/tinymce_assets/'行。這可能會照顧它,或者至少讓你更進一步。

Rails中的路由匹配從頂部開始,因此match '*path'匹配POST到/tinymce_assets,發現它沒有添加語言環境,並通過GET進行重定向。您的應用程序永遠不會到達post '/tinymce_assets'的線路。

+0

這是事實,它應該放在上面匹配「*路徑」,但它仍然觸發一個GET請求 - 的ActionController :: RoutingError (沒有路由匹配[GET]「/ at/tinymce_assets」): –

+0

PS:在開發中它的工作原理 - 我檢查了其他我已經做過的安裝,或許找到了不同的缺陷。但沒有。在它之上 - 它曾經工作。編寫的測試只針對控制器中的操作,並假定它是POST請求。 arghhhh我現在花了整整一天的時間...... –

+0

如果你把'post'/ tinymce_assets'放在'localized'塊之上怎麼辦?如果您可以創建一個具有相同錯誤的精簡應用程序,我可以爲您查看它。您是否在JavaScript中調用'.tinymce(...)'的'uploadimage_form_url'? – PerfectlyNormal

2

解決的問題:

由於我重寫和現有網站,並必須保持URL的標準,我要保持尾隨斜線(這是我在Rails的那樣)。

在我的nginx站點配置中,我重寫了URL的尾部斜線,由於某種原因,這變成了一個縮短問題的兩天的大手筆。

刪除URL重寫中的尾部斜槓在nginx配置 文件中解決了這個問題。

沒有jQuery發送POST請求而不是GET請求!

這裏的nginx(froala & tiny_mce,無論您可以使用):

#Rewrite all URLs with missing slash and no period 
    location/{ 
      rewrite ^([^.]*[^/])$ $1/ permanent; 
    } 
    #Keep your post url untouched 
    location /froala_upload { 
      rewrite $1 permanent; 
    } 

    location /tinymce_assets { 
      rewrite $1 permanent; 
    }