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

Mike P. 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.

mike

Thanks so much Mike.

Works perfectly.

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

g

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.

mike