ruby on rails - Display value from associate table -


i've made voting system app user can vote once post call "idee". here association :

vote

belongs_to :idee belongs_to :user 

user has_many :votes, dependent: :destroy

idee has_many :votes, dependent: :destroy

vote controller

def     user = params[:user_id]     idee = params[:idee_id]     if vote.exists?(:user_id => user) && vote.exists?(:idee_id => idee)      redirect_to :back, :notice => "vous avez déjà voté pour cette idée"     else        vote.create({ idee_id: idee, user_id: user})       redirect_to :back, :notice => "merci d'avoir voté"     end   end 

view

<div class="upvote col-lg-2">    <div class="heart-black hidden-xs">     <p class="like"><%= @idee.vote_id %></p>     <%= link_to "up", {controller: "vote", action: "like", user_id: @current_user, idee_id: @idee}, :class => "upvote-link" %>   </div>  </div>  

my controller works well, can upvote , if voted have notice. each vote stored user_id , idee_id, don't know how can display in view number of vote each idee.

i tried vote.idee_id.count, , i'm not surprise doesn't work. there way want ?


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -