Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:17+00:00 2026-06-08T09:23:17+00:00

Q: How can I fix this problem without hacking the tutorial code too much?

  • 0

Q: How can I fix this problem without hacking the tutorial code too much? I would like to reduce moving away from the tutorial code.

I am working through the online Ruby on Rails Tutorial by Michael Hartl. In Chapter 7 we begin to bring in profile photos using the a Gravatar plugin. (This does not appear compatible with Rails 3 – but this is not the question.)

I have got the plugin working however my Rails App does not show the Gravatar image. It shows a text string. ie It injects the Gravatar code as text rather than an html tag.

Instead of showing the following in the file:

<img class="gravatar" alt="" width="52" height="52" src="http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?rating=PG&amp;size=52" />

It shows this (displaying the text, rather than image):

&lt;img class=&quot;gravatar&quot; alt=&quot;&quot; width=&quot;52&quot; height=&quot;52&quot; src=&quot;http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?rating=PG&amp;amp;size=52&quot; /&gt;

My view file contains:

<%= gravatar_for user, size: 52 %>

The Gravatar plugin contains (gravatar.rb):

def gravatar(email, options={})
  src = h(gravatar_url(email, options))
  options = DEFAULT_OPTIONS.merge(options)
  [:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) }
  "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />"
end

Other info:

I am working on a Windows 7 box running Rails 3.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:23:18+00:00Added an answer on June 8, 2026 at 9:23 am

    Tell Rails that the HTML is trusted (and so shouldn’t be escaped) by using the html_safe method:

    def gravatar_for email, options={}
      # ...
      "<img class=\"#{options[:class]}\" ... />".html_safe
    end
    

    Background: http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/

    Incidentally you can, and probably should, sidestep this issue neatly and entirely by just using Rails’ built-in image_tag helper, which has the bonus effect of getting rid of that long, ugly hard-coded string:

    def gravatar_for email, options={}
      options = DEFAULT_OPTIONS.merge options
      options[:size] = "%{size}x%{size}" % options  # image_tag expects e.g. "48x48"
    
      image_tag gravatar_url(email, options), options
    end
    

    (Don’t let that "..." % options throw you off—it’s basically shorthand for sprintf.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain to me how I can fix this problem. I have two
I can't fix this problem on my listview template: i have the error as
I can't seem to find a way to fix this problem. All I'm doing
My navbar doesn't line up in IE... how can I fix this without using
How can I fix this? REGEX: //REGEX $match_expression = '/Rt..tt<\/td> <td>(.*)<\/td>/'; preg_match($match_expression,$text,$matches1); $final =
How can I fix this error, and install thin or other gems? $ sudo
The Term::Size-module jumbles up the encoding. How can I fix this? #!/usr/bin/env perl use
Can anyone explain the output of this program and how I can fix it?
I'm getting this error in the log.... What can I do to fix this?
How can I fix the view of this twitter on my blogger blog. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.