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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:25:07+00:00 2026-05-17T16:25:07+00:00

I have a partial in my rails app that loads the vote form (It’s

  • 0

I have a partial in my rails app that loads the vote form (It’s just a select with numbers ranging from 1-5). I’m now making another partial that loads up if the user has already voted it’s suppose to be an EDIt partial where you get selected the value that you voted and if you wanted to you could change it. But for some reason is not working, here’s the code for it.

#Finds the vote by passing the user and the article  
<%= @vote = Vote.find_vote_by(current_user,@article) %>

#Renders the partial with the vote variable loaded up with the vote that was found
<%= render :partial => "votes/edit_vote", :locals => {:vote => @vote} %>

And this is the partial

<% form_for(vote, :url => {:controller => 'votes', :action => 'edit'}) do |f| %>

<%= error_messages_for :vote %>

<p><%= f.hidden_field :article_id %></p>
<p>
  <%= f.label :value, "Value for the vote: "%>
  <%= f.select :value, {"1" => "1","2" => "2","3" => "3","4" => "4", "5" => "5"}, :selected => vote.value %>
</p>
<p>
   <%= f.submit "Cloud-it!" %>
</p>

<% end %>

But for some reason the vote variable is not containing anything not the article_id, nor the value method, any ideas?

EDIT1: Per request here’s what’s debug @vote is outputting (It it indeed a sane value)

attributes: 
created_at: 2010-09-02 14:39:04
updated_at: 2010-09-02 14:39:04
id: 1
value: 4
article_id: 1
user_id: 1
attributes_cache: {}

EDIT2

I tried clearing the partial code, in order to output this:

<%= debug @vote%>
<%= @vote.value %>

If i debug @vote it comes out perfect, will all the attributes and such. But whenever i add the second line it, It’s not working it tells me that there’s no .value, i tried .id, .article and nothing is as if it didn’t exist. Any ideas?

EDIT3

Here’s the vote by

 named_scope :find_vote_by, lambda {|user,article| {:conditions => {:user_id => user, :article_id => article}}}
  • 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-17T16:25:08+00:00Added an answer on May 17, 2026 at 4:25 pm

    The reason behind it, it’s that named scopes actually return named scopes, and you can’t access the attributes just like it were a Vote class. I fixed this by changing the way to retrieve the vote and just forgetting about using that named scope. I accomplished it by using:

     <% @vote = current_user.votes.find_by_article_id(@article)%>
    

    which is a Rails method and actually returns a vote class. Then i just passed it to the partial and the magic worked!

    Thank you so much to thenduks, without his help i couldn’t had done it.

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

Sidebar

Related Questions

I have an Ajax form in my Rails app that contains the Recaptcha markup
I have a partial that renders a select box using the following method: <%=
I have this partial code: if ($getRecords = $con->prepare(SELECT * FROM AUCTIONS WHERE ARTICLE_NO
I have a rails app that has picked up a bit of traction, but
Specifically, I have a number of pages in my Rails app that use the
I have a new app (Rails 2.3.8) that uses lots of money fields. I'm
I have a rails app that uses a twitter library to pull in tweets
I have a Rails 3 app that uses a remote/AJAX link to update a
I have a form partial that looks like this: <%= form_for(@pool) do |f| %>
On a Rails 3.1 app, I have a method called user_logged_in? from Devise, which

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.