【问题标题】:Unable To Access Public Images Possible Routing Issue无法访问公共图像 可能的路由问题
【发布时间】:2012-05-03 16:38:18
【问题描述】:

我正在处理一个项目,并尝试在我的一个展示视图中渲染位于公共目录下的一些图像。我可以在我的索引视图上很好地访问这些图像,但对于显示视图来说看起来并不那么容易。

所以在我看来,我有类似以下的内容:

<%= "<img src=\"images/16x16/actions/filesave.png\" class=\"icon" title=\"save\">"%>

这在我的索引视图中可以正常工作,但由于某些奇怪的原因,我在我的显示视图中遇到了这个路由错误:

ActionController::RoutingError(没有路由匹配 [GET] “/uploads/images/16x16/actions/filesave.png”):

我注意到由于某种特殊原因,它在“/images...”之前注入了“/uploads/”路由,这是我的问题的原因,我不知道为什么或如何阻止它。这只发生在我的节目视图中。

现在我的 routes.rb 文件中发生了很多事情,我知道它很难看,但我确实计划在有机会的时候去那里清理它。

resources :upload_images

  get "upload_image/new"

  get "upload_image/index"

  get "upload_image/show"

  get "upload_image/delete"

  resources :help_categories

  resources :global_configs

  resources :competitions

  match '/teams/register', :controller => 'teams', :action => 'register'
  match '/teams/invite_users', :controller => 'teams', :action => 'invite_users'
  match '/teams/view_invitations', :controller => 'teams', :action => 'view_invitations'
  match '/teams/ignore', :controller => 'teams', :action => 'ignore'
  match '/teams/leave_team', :controller => 'teams', :action => 'leave_team'
  resources :teams



  resources :competitions do
    resources :matches
  end

  resources :registers
  resources :players do
    collection do
      post :edit_individual
      put :update_individual
      get :results
    end
  end
  resources :tournaments

  resources :matches

  resources :upload_categories

  resources :uploads, :except => [:new]

  match '/download/:id' => 'uploads#download'

  devise_for :users do    
    match 'logout' => 'devise/sessions#destroy'
  end

  resources :users, :except => [:new] do
    member do
      get 'upload_files'
      get 'delete_files'
    end
  end

  resources :games

  devise_for :videolinks


  resources :topics do
    collection do
      get "mark_all_viewed"
    end
    member do
      get 'show_new'
    end
  end


   resources :posts do
    member do
      get 'quote'
      get 'topic'
    end
  end

  resources :forums do
    member do
      get 'confirm_delete'
    end
  end

  resources :blog_entries, :except => [:index]
  resources :categories
  resources :videolinks
  resources :competition_games
  resources :competitions
  resources :news  
  resources :events 

  match 'uploads/find_uploads' => 'uploads#find_uploads'
  match 'uploads/add_upload_image' => 'uploads#add_upload_image'
  match 'forum_root' => 'forums#index'
  match 'upload_root' => 'uploads#index'
  match 'user' => 'forums#index'
  match 'news_root' => 'news#index'
  match 'topic_post' => 'forums#index'
  match 'quote_post' => 'forums#index'
  match 'new_upload' => 'forums#index'
  match 'videolinks/:id', :to => 'videolinks#show'
  match 'register' => 'users#sign_up'
  match 'login' => 'users#sign_in'

  match 'users/find_users' => 'users#find_users'
  match '/users/get_states/:country' => 'users#states'
  match '/ban/:username' => 'users#ban'
  match '/ban_user/:username' => 'users#ban_user'
  match ':username' => 'users#show'
  match ':username/edit' => 'users#edit'
  match ':username/delete_files_all' => 'uploads#index'
  match ':username/delete_files' => 'users#delete_files'
  match ':username/upload_files' => 'users#upload_files'
  match ':username/password/edit' => 'users#editpass'
  match ':username/edit_file/:id' => 'uploads#edit'
  match '/maketakeadmin/:username' => 'users#maketakeadmin'
  match ':username/destroy' => 'users#destroy'

  root :to => "home#index"

  resources :categories do
    member do
      get 'confirm_delete'
    end
  end

另一位开发人员负责此应用程序的上传部分,它使用回形针。默认情况下,它将上传保存在公共目录中,我们不希望这样,所以他告诉我他做了一些奇怪的修补程序来将上传保存到应用程序根目录下的一个名为“uploads”的私有目录。不确定这是否与它有关。

【问题讨论】:

  • 太棒了,我刚拿到 Tumbleweed 徽章!

标签: ruby-on-rails ruby-on-rails-3.1 routing paperclip show


【解决方案1】:

在路径的开头需要一个正斜杠。

【讨论】:

    【解决方案2】:

    我认为你应该使用这样的东西:

    <%= image_tag "/images/16x16/actions/filesave.png", class: "icon", alt: "save" %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2018-07-29
      • 1970-01-01
      相关资源
      最近更新 更多