LeonB [email protected] wrote:
Thanks! But what does render :locals => {:collection => collection}
do?
Locals are passed into your view as local variables. So if you say
:locals => { :foo => “bar” },
then the variable “foo” in your view will contain the string bar, and
you
can use it like so:
<%=foo%>
What are locals? And why “collection”? Is that something from Ruby? Or
did you make that up? And why twice the “collection”?
“Why twice” should be obvious from my above comment. I picked
“collection”
because that’s what you’re returning, a collection of “additional
people”.
Should I then create a partial that’s called _collection or something
like that?
If you want, then in the view that’s actually displaying it, you could
do
something like:
<%=render :partial => ‘additional_person’, :collection => collection%>
… which would cause that partial to be rendered once for each
additional
person in that collection.
end
Is that all right too?
I guess it’s fine, but since it’s all about declarations and isn’t
thinking about users at all, does it really belong in the user model?
I could see something like this being in the user model if you wanted
to
assert that the declaration actually BELONGED to the user, eg;
def declaration_additional_persons(declaration_id)
payer = DeclarationsPayers.find_by_declaration_id(declaration_id)
if payer
unless payer.user_id == self.id
raise RuntimeError.new, "Declaration payer does not belong to
this user!"
end
return payer.additional_persons
else
return nil # or [] if you dont want to catch nil in your
controller/view
end
end
Cheers,
Tyler