【问题标题】:Ruby on Rails: stripping file extension from image request and redirecting to 404Ruby on Rails:从图像请求中剥离文件扩展名并重定向到 404
【发布时间】:2019-01-02 00:09:20
【问题描述】:

一张图片位于 Rails 目录中的public/images/subDir/X.png

在开发环境中,加载完美。

在生产中,Rails 去除文件扩展名 (.png) 并将请求重定向到 public/images/subDir/X,这会导致 404。

如何让 Rails 不重定向这样的图像请求?

我们正在使用 RoR 3.2.x。

路由文件如下。

Test::Application.routes.draw do


    ###########################################################################
    # Designs
    ###########################################################################
    match '/design' => 'default#design'


    # The priority is based upon order of creation:
    # first created -> highest priority.
    root :to => 'default#home'

    # Sample of regular route:
    #   match 'products/:id' => 'catalog#view'
    # Keep in mind you can assign values other than :controller and :action
    match ':controller(/:action(/:id(.:format)))'

    # Catches all unknown requests
    match '*url' => 'default#error_404'


    # Sample of named route:
    #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
    # This route can be invoked with purchase_url(:id => product.id)

    # Sample resource route (maps HTTP verbs to controller actions automatically):
    #   resources :products

    # Sample resource route with options:
    #   resources :products do
    #     member do
    #       get 'short'
    #       post 'toggle'
    #     end
    #
    #     collection do
    #       get 'sold'
    #     end
    #   end

    # Sample resource route with sub-resources:
    #   resources :products do
    #     resources :comments, :sales
    #     resource :seller
    #   end

    # Sample resource route with more complex sub-resources
    #   resources :products do
    #     resources :comments
    #     resources :sales do
    #       get 'recent', :on => :collection
    #     end
    #   end

    # Sample resource route within a namespace:
    #   namespace :admin do
    #     # Directs /admin/products/* to Admin::ProductsController
    #     # (app/controllers/admin/products_controller.rb)
    #     resources :products
    #   end

    # You can have the root of your site routed with "root"
    # just remember to delete public/index.html.
    # root :to => "welcome#index"

    # See how all your routes lay out with "rake routes"

    # This is a legacy wild controller route that's not recommended for RESTful applications.
    # Note: This route will make all actions in every controller accessible via GET requests.
    # match ':controller(/:action(/:id(.:format)))'
end

【问题讨论】:

  • 你的 routes.rb 是什么样子的?
  • 重定向是由 Rails 还是你的应用服务器如 nginx 完成的?
  • @LeninRajRajasekaran 使用路线文件更新了问题。这就是您确定谁进行重定向的方式吗?
  • @KyleDecot 更新了问题。谢谢!
  • production.rb 中的config.serve_static_files 是什么?

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

问题是由图像名称中的拼写错误引起的,但不清楚文件扩展名被删除的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 2022-11-22
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多