0

非常简单的 ruby​​ on rails 问题。我正在制作一个应用程序,其中有讨论,用户可以对其发表评论,我希望他们的头像出现在他们的评论旁边。怎么做呢?谢谢!

_discussion.html.erb

<% content_for :script do %>
    <%= javascript_include_tag 'hover_content' %>
<% end %>

<% @micropost = Micropost.new %>
<% @micropost.discussion_id = discussion.id %>

<li>
  <div class = "intro-bar"><span class = "intro"><%=discussion.intro %></span></div>
  <div class = "content-bar">
    <span class = "content"><%= discussion.content %></span>
  </div>
  <input type='button' id='hideshow' value='hide/show'>
    <div class = "buttons">
      <!--<div class = "vote-neg"><%= link_to "Break Up", signup_path,class: "btn btn-large btn-breakup" %></div>-->
      <!--<div class = "vote-plus"><%= link_to "Stay Together", signup_path,class: "btn btn-large btn-staytogether" %></div>-->
    </div>

</li>

<span class = "timestamp">
    Posted <%= time_ago_in_words(discussion.created_at) %> ago.
  </span>

            <% if signed_in? %>
                <div class = "row">
                  <aside class = "span4">
                    <section>
                      <%= form_for(@micropost) do |f| %>
                          <%= render 'shared/error_messages', object: f.object %>
                          <div class="field">
                            <%= f.text_area :content, placeholder: "Post a comment" %>
                          </div>
                          <%= f.hidden_field :discussion_id%>

                          <%= f.submit "Break Up", class: "btn btn-large btn-breakup",:name => "break_up" %>
                          <%= f.submit "Stay Together", class: "btn btn-large btn-staytogether", :name => "stay_together" %>
                              <% end %>
                              </section>
                              </aside>
                              </div>
                          <% end %>

<div class = "comments">
  <% discussion.microposts.each do |micropost| %>
      <li>
        <div class = "comment-pic"></div>
        <div class = "post-comment"><%= micropost.content%></div>
      </li>
  <% end %>
</div>

用户展示页面

<% provide(:title, @user.username) %>
<div class="row">
  <aside class="span4">
    <section>
      <h1>
        <%= gravatar_for @user %>
        <%= @user.username %>
      </h1>
    </section>
  </aside>
</div>
<div id = "user_content">
  <p>
    <%= @user.email %><br/>
    <%= @user.age %> years old <br/>
    <%= @user.sex %> <br/>
  </p>
</div>
</div>
4

1 回答 1

0

观看此 railscasts 视频以了解其实施。

RailsCasts Gravatar 教程

于 2013-06-24T19:10:43.463 回答