Forum: Ruby on Rails MVC

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
MVC
208af8ce969fdf68f866abd96485c6fe?d=identicon&s=25 mift99 (Guest)
on 2009-04-09 13:56
(Received via mailing list)
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
648a71a35ce6e4a1c5cd63451a2a20df?d=identicon&s=25 Gavin (Guest)
on 2009-04-09 14:09
(Received via mailing list)
could you explain the birthday calendar method a little better?
208af8ce969fdf68f866abd96485c6fe?d=identicon&s=25 mift99 (Guest)
on 2009-04-09 19:57
(Received via mailing list)
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!
Ac1c51f25718910e4a6d19ee44b5d465?d=identicon&s=25 Kevin Elliott (Guest)
on 2009-04-09 21:00
(Received via mailing list)
On Apr 9, 2009, at 10:56 AM, mift99 wrote:

>
> 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
208af8ce969fdf68f866abd96485c6fe?d=identicon&s=25 mift99 (Guest)
on 2009-04-10 13:56
(Received via mailing list)
Hi,

I did end up making a named scope. This feature is really nice!

Thanks guys, really helped me a lot!
This topic is locked and can not be replied to.