轨。 TinyMCE ImageUpload正在开发中请求GET而不是POST

时间:2015-09-27 00:41:57

标签: ruby-on-rails ruby-on-rails-4 tinymce tinymce-rails

我使用TinyMCE Imageupload在rails上工作。

它在开发中运行得很好(有趣的是,它曾用于生产)。问题是在生产时它会发出错误的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]

此处列出了此应用程序中使用的完整宝石列表:

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

希望这有助于揭示情况。 :)

2 个答案:

答案 0 :(得分: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;
    }

答案 1 :(得分:1)

您应该交换最后一个match '*path'行和post '/tinymce_assets/'行。这可能会照顾它,或者至少让你更进一步。

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