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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:27+00:00 2026-05-21T04:01:27+00:00

i moved from php to rails3, and i still think it was a good

  • 0

i moved from php to rails3, and i still think it was a good decision! Anyway I have some models:

users
questions
answers
question_id
votes
user_id
answer_id

model for users:

has_many :questions
has_many :votes

model for questions:

belongs_to :user
has_many :answers, :dependent => :destroy
accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true

model for answers:

belongs_to :question
has_many :users, :through => :votes, :dependent => :destroy
has_many :votes

model for votes:

belongs_to :answer
belongs_to :user

Now my question, once a user has voted on an answer, the voting for that user and for that specific question should be closed…

I use devise and cancan for users and authorization in the rest of my project…

In my view it should look something like:

<% unless current_user.question_answered.include? question %>

and then do the script where i render the vote buttons…

In my votes model i have an
answer_id and a user_id, i know the
current_user.id and the current question.id
so if the vote.user_id has the vote.answer_id that is in the current question.id than it shouldn’t render my button making script… aarghh but how to put this to work…?

Thanks very much in advance!
And best regards,
Thijs

  • 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-21T04:01:28+00:00Added an answer on May 21, 2026 at 4:01 am

    I would personally go outside of devise and write my own method. I think it’s a little cleaner and easier to understand. You’ll also guarantee with this method that you are only performing a single fast query to your DB. By asking current_user.questions_answered you are querying the database for all questions that a user has answered, which is potentially a much larger result set than checking if the user has voted on the current question:

    class User
      def can_vote_on? question
        !question.answers.joins(:votes).where('votes.user_id = ?', id).exists?
      end
    end
    

    You can then adjust your view to:

    <% if current_user.can_vote_on?(question) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At some point I must have moved files from one location to another using
I have just moved from using php mvc frameworks to rails and have been
Over the last year I have moved from a beginner PHP developer to a
I've moved from SeleniumRC to WebDriver for nearly two years. But I have to
I just moved from an Ubuntu PHP workstation dev environment back to Windows and
I just got a strange problem. I am including some files from my index.php,
I have some existing projects that were built upon a deprecated PHP framework, and
This is Common task In PHP and other programming languages.I moved from PHP developer.
I'm new to Django, moved from PHP with Propel ORM engine. So here is
i have 2 objects, which are associated arrays from PHP in JSON. They have

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.