def already_voted_arts !Vote.find_by_user_id_and_category(current_user.id, "Arts").blank? end
On Dec 2, 10:45 am, DanC <d.m.coleg...@durham.ac.uk> wrote: > Hi all, > > I am trying to get my head around using view helpers. > > My app has a Posters Model and I am allowing Users to vote on the best > poster using a Votes model. Posters are in three categories. > > I want to build a filter to make sure people can only vote once in > each Poster Category. > > The Vote entry has user_id (integer), poster_id(integer), category > (string) > > On a simple level I want to start with a filter in my view file to > only display the 'Vote' link if an entry does not exist for the > current_user and relevant category. > > I tried adding the following to my PostersHelper but kept getting > wrong number of arguments (0 for 1) > > code below. > > Any advice on this type of filter would be much appreciated. > > ------------------------ > class PostersController < ApplicationController > ..... > helper :posters > ..... > > end > ---------------------- > module PostersHelper > def already_voted_arts > Vote.exists?['user_id = ?', current_user.id AND 'category = ?', > "Arts"] > end > end > --------------------- > <h2>Arts and Humanities</h2> > <%if already_voted_arts%> > <p>You have already voted in this category</p> > <%else%> > <p><b><%=link_to "Place your Arts and Humanities vote now", > poster_arts_vote_path%></b></p> > <%end%> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.