gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:36 24 4
gpt4 key购买 nike

我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com