Greg Plumbly
2007-Sep-21  18:25 UTC
moving logic to controller in for loop - newbie question
Hi,
Im new at this. I have something like this in my list view
<% for property in @properties %>
..
<%= number_to_currency((property.current_value  -
property.mortgage_amount), {:unit => "£"}) %>
<% end %>
which has the desired effect.
However I understand I should be putting this sort of logic into a
controller.
Ive tried this in my controller
@get_property_equity = Property.find(:id).current_value -
Property.find(:id).mortgage_amoount
This works(sort of) if I enter an id manually but I am not sure how to
pass the id in my loop in my view, indeed if thats what I should be
doing?
Any help greatly appreciated
g
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Mike Perham
2007-Sep-21  18:43 UTC
Re: moving logic to controller in for loop - newbie question
Greg Plumbly wrote:> Hi, > > > Im new at this. I have something like this in my list view > > <% for property in @properties %> > .. > > > <%= number_to_currency((property.current_value - > property.mortgage_amount), {:unit => "£"}) %> > <% end %> > > which has the desired effect. > > > However I understand I should be putting this sort of logic into a > controller. > > Ive tried this in my controller > > @get_property_equity = Property.find(:id).current_value - > Property.find(:id).mortgage_amoount > > This works(sort of) if I enter an id manually but I am not sure how to > pass the id in my loop in my view, indeed if thats what I should be > doing? > > Any help greatly appreciated > > gGreg, it seems like this is something better suited as a model attribute. Put this on your Property model: def current_equity self.current_value - self.mortgage_amount end Then in your view, you can just do this: number_to_currency(property.current_equity, {:unit => "£"}) Try that and see what happens. mike -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Plumbly
2007-Sep-21  18:47 UTC
Re: moving logic to controller in for loop - newbie question
Mike Perham wrote: snip> > Greg, it seems like this is something better suited as a model > attribute. Put this on your Property model: > > def current_equity > self.current_value - self.mortgage_amount > end > > Then in your view, you can just do this: > > number_to_currency(property.current_equity, {:unit => "£"}) > > Try that and see what happens. > > mikeThanks so much Mike. Works perfectly. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---