0

I am developing based on Ruby on Rails tutorial by Michael Hartl, with the help of Devise and Forem. The code is visible at https://github.com/fchampreux/ODQ_Web. The web site is visible at 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:

<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. Each of them renders correctly the image.

The dynamic page produced by Forem does not render the image. This page actually is not directly listed in the routes.rb nor in a controller.

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:

config/initializers/forem.rb

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

Can you please help me to understand and solve this issue ?

user1185081
  • 1,898
  • 2
  • 21
  • 46

2 Answers2

1

config/initializers/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

Brooks
  • 286
  • 1
  • 9
0

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:

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

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:

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

which produces the html:

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

Examine the src attribute of the <img> tag. Now, compare the src attributes in those <img> tags to the src attribute in your <img> tag:

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.

7stud
  • 46,922
  • 14
  • 101
  • 127