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

  • SEARCH
  • Home
  • 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 7504985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:45:36+00:00 2026-05-29T21:45:36+00:00

I have a parameter in my comments called total_votes (composed of integers). This is

  • 0

I have a parameter in my comments called total_votes (composed of integers).
This is how I order comments by the most voted and apply will paginate at the same time:

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 %>

I would like to create a link_to action so that I can manipulate this part:

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

So that I can archive something like this:

mysite/posts/93?order_by=votes

and or this (order_by + will_paginate):

mysite/posts/93?order_by=votes&page=2

or something like that.

Any suggestions about how to accomplish code this in the controller and view (Please let me know if this is not the best way of doing it)?

  • 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-05-29T21:45:39+00:00Added an answer on May 29, 2026 at 9:45 pm

    EDIT:

    This Railscasts is what you want!

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

Sidebar

Related Questions

I have seen this question in SO several times. Most of cases user called
I have a parameter like this: rightOperand:(const NSDecimal*)rightOperand how could I provide a value
In my application I have a string parameter called shop that is required in
I have a stored procedure (sproc) called resetflags. It takes an int parameter. Another
I have a function that takes another function as a parameter. Something like this
I have a parameter @Department and set its value in the Dataset to =Join(Parameters!Department.Value,,)
How can I have a parameter to one JS function be Function Name with
I have added a parameter to my report with the option Allow Multiple Values
I have an object parameter and I need to check if the object implements
I have a get-parameter with name controller . When I try to pass it

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.