2012-02-09 5 views
0

私のコメントには、total_votes(整数で構成)というパラメータがあります。will_paginate + order_byパラメータ(Rails)のlink_toアクションの作成

show.rb:

def show 
    @post = Post.find(params[:id]) 
    @comments = @post.comments.paginate(:page => params[:page], 
             :per_page => 5).order('total_votes DESC, 
                   created_at DESC') 
    end 

show.html.erb:

<% @comments.map do |comment| %> 
    <div class="comment-<%= comment.id %>"> 
    <p> 
    <b>Comment:</b> 
    <%= comment.content %> 
    </p> 
    <p> 
    <b>Vote:</b> 
    <span class="vote-count"><%= comment.total_votes %></span> 

    <div class='voted-user'> 
     <% comment.votes.each do |vote| %> 
     <%= link_to vote.user.username, vote.user %> 
     <% end %> 
    </div> 
    </p> 
    <p> 
    <b>Commenter</b> 
    <%= link_to comment.user.username, comment.user %> 
    </p> 
    <p> 
    <b>Link</b> 
    <%= link_to "Show Post Comment", [@post, comment] %> 
    </p> 
    <p> 
    <b>Vote</b> 
    <%= link_to "Vote Up", vote_up_path(comment, :votable_type => "Comment"), :remote => true, :class => "vote-up" %><br /> 
    </p> 
    </div> 
<% end %> 

<%= will_paginate @comments %> 
これは私が最も投票によってコメントを注文すると同時に、ページ付けます適用方法です

この部分を操作できるように、link_toアクションを作成します。

個人用サイト/記事/ 93 ORDER_BY =投票

とか、この(ORDER_BY + will_paginate):

私はこのような何かをアーカイブすることができるように

@comments = @post.comments.paginate(:page => params[:page], 
            :per_page => 5).order('THIS_PART') 

mysite/posts/93?order_by = votes &ページ= 2

またはそのようなもの。

これをコントローラとビューでコード化する方法についての提案があります(これが最善の方法でない場合は教えてください)。

答えて

1

EDIT:

このRailscastsは何をしたいです!

+0

しかし、私はまたコントローラとビューでそれをコード化する方法が必要です。 – alexchenco

関連する問題