0

在 Devise 和 Forem 的帮助下,我正在基于 Michael Hartl 的 Ruby on Rails 教程进行开发。该代码在https://github.com/fchampreux/ODQ_Web可见。该网站可见于http://www.opendataquality.org

在我的标题中,我包含了一张图片:

<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>
...

它工作正常,并为我的每个页面生成以下 html 代码:

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

所有静态页面都在一个专用文件夹中,由 static_pages_controller 生成。他们每个人都正确地渲染了图像。

Forem 生成的动态页面不渲染图像。此页面实际上并未直接列在 routes.rb 或控制器中。

路线.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

Forem 初始化程序配置为应用程序布局:

配置/初始化程序/forem.rb

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

你能帮我理解和解决这个问题吗?

4

2 回答 2

1

配置/初始化程序/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

取消注释这些行并将“forem”更改为“application”,假设您的标题在您的应用程序布局中

于 2014-10-21T00:30:19.340 回答
0

如果您访问 Forem 列为 Forem 用户的几个网站View Source,然后查找<img>标签,您会看到如下内容:

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

检查<img>标签的 src 属性。

然后,如果我查看我自己的 Ruby on Rails 教程应用程序,它不使用 Forem,我在 home.html.erb 页面上有以下内容:

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

生成html:

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

检查<img>标签的 src 属性。现在,将这些<img>标签中的 src 属性与标签中的 src 属性进行比较<img>

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

因此,我会考虑在路径的开头使用“/”。

于 2014-10-22T01:00:08.250 回答