簡體   English   中英

圖片未顯示在Rails應用中

[英]image not displaying in rails app

我的Rails應用程序存在一個非常令人困惑的問題。 我正在嘗試在頁面上顯示圖像,並且我知道該路徑是正確的。 這由“ test.html”驗證,其整體為:

<img src="/Users/xxxxx/MHE_website/app/assets/images/aggi5.jpg" >

當我在本地加載此頁面時,我看到了圖片。 但是,當我將其放入Rails應用程序時,不會加載完全相同的文本。 是什么賦予了? 我注意到當我在本地托管進行開發時,在終端中收到以下錯誤消息:

ActionController::RoutingError (No route matches [GET] "/Users/xxxxx/MHE_website/app/assets/images/aggi5.jpg"):

這是什么意思? 我從來沒有做過此事。 以下是我的Gemfile,這可能相關也可能無關,但我很茫然。

source 'https://rubygems.org'

#toggle this on for dev mode
# group :development, :test do 
#   gem 'sqlite3'
# end

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

gem 'owlcarousel-rails', '~> 1.1.3.3'
gem 'bootstrap-sass', '2.3.2.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development


group :development, :test do 
  gem 'sqlite3'
end

group :production, :staging do
    gem 'pg'
    gem 'rails_12factor'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

您需要使用image_tag幫助器在您的應用程序中顯示圖像。 請參閱文檔

您應該在視圖中使用以下內容:

<%= image_tag( 'aggi5.jpg' ) %>

嘗試將圖像的權限更改為777 它應該工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM