开发者

ruby on rails gravatar_image_tag

I am following t开发者_如何学Gohe railstutorial.org tutorial. While I am able to see the gravatar on the webpage, my rspec test is failing.

Here is the user_controller_spec.rb test:

describe "GET 'show'" do

  before(:each) do
    @user = Factory(:user)
  end

  it "should be successful" do
    get :show, :id => @user
    response.should be_success
  end

end

Here is the relevant show.html.erb file:

<table class="profile" summary="Profile information">
  <tr>
    <td class="main">
      <h1>
        <%= gravatar_image_tag(@user.email) %>
        <%= @user.name %>
      </h1>
    </td>
    <td class="sidebar round">
      <strong>Name</strong> <%= @user.name %><br />
      <strong>URL</strong> <%= link_to user_path(@user), @user %>
    </td>
  </tr>
</table>

I get an error stating "undefined method 'gravatar_image_tag'. I already installed the corresponding gem by executing "gem install gravatar_image_tag", added it to my gemfile, and also executed "bundle install". It is listed as installed when I execute "gem list"

I have been trying to debug this for several hours now. Any help would be appreciated. Thanks in advance. BTW, I'm running 32-bit Windows 7 with GIT Bash, RubyInstaller-1.9.2-p0.

Error message:

ruby on rails gravatar_image_tag


Following the same tutorial, I had the same undefined method 'gravatar_image_tag' error, but a different solution from the accepted one above (my gem was in the correct place in the Gemfile, so that wasn't the problem).

Just had to restart the server (Ctrl C then rails server), and then everything was fixed.


Is the gravatar_image_tag gem global to all environments in your gemfile? If you have it in a group :development, :production block, or something similar, it wouldn't be available in test.

And I haven't tried it, but your line:

get :show, :id => @user

seems like it needs to be:

get :show, :id => @user.id


I'm the author of the gem. Can you open an issue on the github page http://github.com/mdeering/gravatar_image_tag/issues with the version of rails and a gem list for me. I will see if I can resolve the issue for you and post an answer back here.

I have some pre-release versions of the gem that I could push out to gemcutter that might resolve the issue already.

Cheers, Mike D.


If you use Spork as DRB server try to restart it, that helped me! (i'm also following Hartls PDF).


I had the same issue, a simple restart fixed it.


The gravatar gem file has been updated since the release of Michael Hartl's PDF.

gem 'gravatar_image_tag'

Include that in your Gemfile and then restart your rails server using

rails s

That worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜