1

我正在使用TinyMCE Imageupload在轨道上工作。

它在开发中工作得很好(有趣的是,它过去也可以在生产中工作)。问题是在生产中它发出错误的 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 => false - 因为它在 environment.rb 中设置为 true

问题:

为什么生产到站点决定触发 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]

该设置曾经有效,但不再有效(在没有明显变化之后 - 虽然我目前也在通过我的 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]

这里是此应用程序中使用的 gem 的完整列表:

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

希望这有助于阐明情况。:)

4

2 回答 2

2

问题的解决方案:

由于我正在重写现有站点并且必须保留 URL 标准,因此我必须保留尾部斜杠(我在 Rails 中这样做)。

在我的 nginx 站点配置中,我用尾部斜杠重写了 URL,由于某种原因,这变成了缩小问题范围的两天大屠杀。

在 nginx 配置文件中删除 URL 重写中的尾部斜杠解决了该问题。

没有 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;
    }
于 2015-09-29T03:44:22.197 回答
1

您应该交换最后match '*path'一行和该post '/tinymce_assets/'行。这可能会解决它,或者至少让你走得更远。

Rails 中的路由从顶部开始匹配,因此match '*path'匹配 POST 到/tinymce_assets,发现它没有添加语言环境,并通过 GET 进行重定向。您的应用程序永远不会到达post '/tinymce_assets'.

于 2015-09-28T09:27:14.017 回答