0

これは私の最初のRailsアプリを完成させるための最後の残りのアイテムであり、いくつかの助けが必要です。各ユーザープロファイル(localhost:3000 / users / username)には、ユーザーが行った投稿のリストがあります。各投稿に関連付けられているのはコメントです。したがって、post_id:3にコメントを付けることができます。

すでにビューフォームで機能していますが、各投稿の下にある[コメント]リンクをクリックしたときに、代わりにポップアップにコメントを表示する必要があります。ポップアップを表示するjQueryベースのライトボックスであるfaceboxをすでに適用しました。

現在show.html.erbに表示されているものをポップアップに移動する必要があります。

_post.html.erbにレンダリングされる_comment_form.html.erbがあります

  <%= link_to #, :rel => "facebox-#{post.id}" do %>
  +<%= post.comments.count.to_s %>
<% end %>
 <div class ="ItemComments"><% if post.comments.exists? %>
   <% post.comments.each do |comment| %>
   <%= image_tag("http://www.gravatar.com/avatar.php?gravatar_id=#{Digest::MD5::hexdigest(comment.user.email)}" %>
   <span class="users"><%= link_to comment.user.name, comment.user %></span>
   <span class="timestamp"><%= time_ago_in_words(comment.created_at) %> ago</span>
   <span class="content2"><%= comment.comment_content %></span>
   <% end %>
 <% end %></div>

上記は、以下を使用して_post.html.erbにレンダリングされます。

<%= render 'shared/comment_form', post: post if signed_in?%>

次に、show.html.erbにレンダリングします

この行を使用しようとしていますが、何にリンクしますか?

    <%= link_to #, :rel => "facebox-#{post.id}" do %>
  +<%= post.comments.count.to_s %>
<% end %>

これはshared/_comment.html.erbです

<% if post.comments.exists? %>
  <% post.comments.each do |comment| %>
  <%= image_tag("http://www.gravatar.com/avatar.php?gravatar") %>
    <%= link_to comment.user.name, comment.user %>
            <span class="timestamp"><%= time_ago_in_words(comment.created_at) %> ago</span>
    <span class="content2"><%= comment.comment_content %></span>
    <% end %>
<% end %>
4

1 に答える 1

0

これを行う1つの方法は、コメントを非表示のdivにレンダリングし、そのdivにIDを与えることです。次に、#の後にidを使用して、divのIDへのリンクを指定します。次のようになります。

_post.html.erb

<%= link_to "#comments", :rel => "facebox" do %>
    <%= post.comments.count.to_s %>
<% end %>
<div id="comments">
    <%= render 'shared/comment_form', post: post if signed_in?%>
</div>

CSS

#comments {
    display: none;
}

Faceboxのドキュメントで「Divs」の見出しを参照してください。

于 2013-03-14T07:53:36.600 に答える