html - 图像未显示在 Rails 应用程序中

标签 html css ruby image

我的 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 帮助程序在您的应用程序中显示图像。参见 documentation .

你应该在你的 View 中使用这样的东西:

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

关于html - 图像未显示在 Rails 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28519366/

相关文章:

javascript - 如何通过ajax将表格单元格值传递给php

javascript - 使用 JavaScript 确定元素的宽度是固定宽度还是百分比宽度

javascript - Chrome - "Trying to load script from unauthenticated sources"

ruby - 类变量和扩展模块

ruby-on-rails - 在 Rails 5+ 中禁用 sprocket 资源缓存

javascript - WebSocket 在发送时关闭

javascript - 如何将数组作为参数从 Ipython 笔记本传递到包含一些 javascript 函数的 html 文件?

html - 如何在重组文本中注释字符串?

javascript - 我的子菜单未在 safari 中显示,但在 chrome 和 firefox 中显示

ruby - 如何实现 Watir 类(例如 PageContainer)?