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 9154113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:22:41+00:00 2026-06-17T12:22:41+00:00

I am following schneems’s great intro to Rails tutorial on creating a Reddit clone,

  • 0

I am following schneems’s great intro to Rails tutorial on creating a Reddit clone, and want to expand the “voting” structure to work not only for questions, but for comments as well, and was having difficulty figuring out how to pass into the controller both question_id and comment_id so it could vote up or down accordingly, rather than restricting the usage to only question_id.

Currently, there is only a create function in my VotesController, defined as the following:

  def create
    @vote = Vote.where(:question_id => params[:vote][:question_id], :user_id => current_user.id).first #the question_id is baked right in.. 
    if @vote
      @vote.up = params[:vote][:up]
      @vote.save
    else
      @vote = current_user.votes.create(params[:vote])
    end
    redirect_to :back
  end

Thanks for your help!

  • 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-06-17T12:22:42+00:00Added an answer on June 17, 2026 at 12:22 pm

    Well, when you try to vote on a comment, that would mean that params[:vote] should contain a :comment_id instead of a :question_id, right?

    So your where statement needs to either be

    # for a question
    where(:question_id => params[:vote][:question_id], :user_id => current_user.id)
    
    # for a comment
    where(:comment_id => params[:vote][:comment_id], :user_id => current_user.id)
    

    You approach this in various ways, like by checking if params[:vote].has_key?(:question_id), but an easy option would be to use Hash#slice:

    where(params[:vote].slice(:question_id, :comment_id).merge(:user_id => current_user.id))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following the TkDocs Tutorial (http://www.tkdocs.com/tutorial/widgets.html#checkbutton) I am trying to set up a check box,
Following this tutorial http://msdn.microsoft.com/en-us/vstudio/hh543922.aspx , I'm trying to use the ReplaceNode method that should
Following a post of similar question (which doesn't work), I declared a instance of
Following is the repetivite html structure that i have in my template: <div class=mystyle
Following is my code. The items array has 12 elements. I want to add
Following the tutorial @ http://kerkness.ca/kowiki/doku.php?id=example_of_a_multi-language_website I need to override the Request class, but there
Following this post Factory Girl If you can’t upgrade to Ruby 1.9 and Rails
following situation: <body> <div style=position:fixed; width:100%>[place holder for header]</div> <div style=position:relative;width:100%;margin-top:100px>[content]</div> </body> I need
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to

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.