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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try this as code: module PostersHelper def already_voted_arts Vote.exists?[''user_id = ? AND category = ?'', current_user.id , "Arts"] end end On Wed, Dec 2, 2009 at 4:45 PM, DanC <d.m.colegate-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mmm. I still get wrong number of arguments (0 for 1) Extracted source (around line #8): 5: <p>Due to the large number of entries we received voting has been extended until 31 January 2010. Thank you to all of our <%=link_to "sponsors", poster_sponsors_path%> for supporting our competition.</p> 6: 7: <h2>Arts and Humanities</h2> 8: <%if already_voted_arts%> 9: <p>You have already voted in this category</p> 10: <%else%> 11: <p><b><%=link_to "Place your Arts and Humanities vote now", poster_arts_vote_path%></b></p> On 2 Dec, 15:51, "C+++" <christiaan.vandenp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this as code: > > module PostersHelper > def already_voted_arts > Vote.exists?[''user_id = ? AND category = ?'', current_user.id , "Arts"] > end > end > > On Wed, Dec 2, 2009 at 4:45 PM, DanC <d.m.coleg...-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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...-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fantastic - that worked. Thank you. Dan On Dec 3, 4:29 am, David <furb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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...-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> wrote: > > > Hi all, > > > I am trying to get my head around usingviewhelpers. > > > 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 myviewfile 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.