Hi, i am wondering about the MVC pattern, I havent worked with that for a long time and before I break it I would like to ask your advice... if I have a birthday calender visible in nearly every view where would I put the controller? I was thinking about putting the method it into application controller.. but how do you call that from the view? Thanks, Philipp --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
could you explain the birthday calendar method a little better? On Apr 9, 12:49 pm, mift99 <philipp.knobelsp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > i am wondering about the MVC pattern, I havent worked with that for a > long time and before I break it I would like to ask your advice... > > if I have a birthday calender visible in nearly every view where would > I put the controller? I was thinking about putting the method it into > application controller.. but how do you call that from the view? > > Thanks, > Philipp--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Thanks, so the solution is, just for everyone else facing the same proplems, (at least I hope): Write a helper method def birthday_helper (number_of_resutls) costumers_with_upcoming_birhtday = Costumer.find_near_birthday costumers_with_upcoming_birhtday= costumers_with_upcoming_birhtday [0..number_of_resutls] end and then call it from the view <% birthday_helper(10).each do |costumer| %> <tr> <td><%=link_to costumer.last_name, costumer %></td> <td><%=link_to costumer.birthday, costumer %></td> <br /> </tr> <% end %> Thanks for the help! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 9, 2009, at 10:56 AM, mift99 wrote:> so the solution is, just for everyone else facing the same proplems, > (at least I hope): > > Write a helper method > > def birthday_helper (number_of_resutls) > costumers_with_upcoming_birhtday = Costumer.find_near_birthday > costumers_with_upcoming_birhtday= costumers_with_upcoming_birhtday > [0..number_of_resutls] > end > > and then call it from the view > > <% birthday_helper(10).each do |costumer| %> > <tr> > <td><%=link_to costumer.last_name, costumer %></td> > <td><%=link_to costumer.birthday, costumer %></td> > <br /> > </tr> > <% end %>You might take note that there are a lot of misspellings of "birthday" (birhtday), so this code won''t run, but you''ve probably already noticed that. Also, why not make use of a named scope with a parameter instead of a helper? Such as: class Customer named_scope :upcoming_birthdays, lambda { |number_of_results| { :conditions => { [''your conditions for nearing birthdays''] }, :limit => number_of_results } } end Then in any controller, view or runner you could do Customer.upcoming_birthdays(10) -Kevin --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I did end up making a named scope. This feature is really nice! Thanks guys, really helped me a lot! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---