简体   繁体   English

Ruby on Rails 4:为什么我的标题图像显示在除一页之外的所有页面上?

[英]Ruby on Rails 4: Why is my header image displaying in all pages but one?

I am developing based on Ruby on Rails tutorial by Michael Hartl, with the help of Devise and Forem. 在Devise和Forem的帮助下,我基于Michael Hartl的Ruby on Rails教程进行开发。 The code is visible at https://github.com/fchampreux/ODQ_Web . 该代码在https://github.com/fchampreux/ODQ_Web上可见。 The web site is visible at http://www.opendataquality.org 该网站位于http://www.opendataquality.org。

In my header, I included an image: 在标题中,我包含一张图片:

<header>
...
  <div class="row">
    <div class="col-md-3">
      <h5><img style="position:relative; left:10px; top:10px; vertical-align:bottom" alt="ODQ Logo" src="assets/ODQ_Logo.png"></h5>
    </div>
...

It works fine, and generates following html code for each one of my pages: 它工作正常,并为我的每一页生成以下html代码:

<img style="position:relative; left:10px; top:10px; vertical-align:bottom" alt="ODQ Logo" src="assets/ODQ_Logo.png">

All the pages that are static are in a dedicated folder, and produced by the static_pages_controller. 所有静态页面均位于专用文件夹中,并由static_pages_controller生成。 Each of them renders correctly the image. 它们每个都正确渲染图像。

The dynamic page produced by Forem does not render the image. Forem生成的动态页面不会渲染图像。 This page actually is not directly listed in the routes.rb nor in a controller. 实际上,该页面未直接在routes.rb中或控制器中列出。

routes.rb 的routes.rb

ODQWeb::Application.routes.draw do

# This line mounts Forem's routes at /forums by default.
# This means, any requests to the /forums URL of your application will go to Forem::ForumsController#index.
# If you would like to change where this extension is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Forem relies on it being the default of "forem"
mount Forem::Engine, :at => '/forums'

devise_for :users
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
root to: 'static_pages#welcome'
get '/welcome',   to: 'static_pages#welcome'
get '/partners',  to: 'static_pages#partners'
get '/careers',   to: 'static_pages#careers'
get '/products',  to: 'static_pages#products'
get '/services',  to: 'static_pages#services'
get '/solutions', to: 'static_pages#solutions'
end

The Forem initializer is configured for application layout: Forem初始化程序针对应用程序布局进行配置:

config/initializers/forem.rb 配置/初始化/ forem.rb

Rails.application.config.to_prepare do
  Forem.layout = "application"
end

Can you please help me to understand and solve this issue ? 您能帮我理解和解决这个问题吗?

config/initializers/forem.rb 配置/初始化/ forem.rb

# Rails.application.config.to_prepare do
#   If you want to change the layout that Forem uses, uncomment and customize the next line:
#   Forem::ApplicationController.layout "forem"
#
# end

uncomment these lines and change "forem" to "application" assuming your header is in your application layout 取消注释这些行,并假设标题位于应用程序布局中,将“ forem”更改为“ application”

If you go to a couple of the websites that Forem lists as users of Forem, then View Source , then look for <img> tags, you will see things like this: 如果您访问Forem列出为Forem用户的几个网站,然后View Source ,然后查找<img>标签,您将看到类似以下内容:

<header>  
<a class="logo" href="/">
<img alt="Huntington&#39;s Disease Youth Organization"  
 src="/assets/logo-57ec7c34b82b9d8e2875b30929d99838.png" /></a>

Examine the src attribute of the <img> tag. 检查<img>标记的src属性。

Then if I look at my own app for the Ruby on Rails Tutorial, which doe not use Forem, I have the following on the home.html.erb page: 然后,如果我查看我自己的不使用Forem的Ruby on Rails教程应用程序,那么home.html.erb页面上将显示以下内容:

<%= link_to image_tag('rails.png', alt: 'Rails'), 'http://rubyonrails.org/' %>

which produces the html: 产生html:

<a href="http://rubyonrails.org/"><img alt="Rails" src="/assets/rails.png" /></a>

Examine the src attribute of the <img> tag. 检查<img>标记的src属性。 Now, compare the src attributes in those <img> tags to the src attribute in your <img> tag: 现在,相比于那些在src属性<img>标签来在您的src属性<img>标签:

src="/assets/rails.png"
src="/assets/logo-57ec7c34b82b9d8e2875b30929d99838.png" 
src="assets/ODQ_Logo.png">  #<===YOUR PATH

So, I would consider using a '/' at the beginning of your path. 因此,我会考虑在路径的开头使用'/'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM