Ruby on Rails Saturday, May 23, 2015

Thank you very, very much!

a = Lender.find('7oV71d1oVtxfyS9Ra6hnUtNe31N').addresses.select('state_id_string')
a.blank?

On Friday, May 22, 2015 at 5:05:25 PM UTC-4, Colin Law wrote:
On 22 May 2015 at 20:28, Elizabeth McGurty <emcg...@gmail.com> wrote:
> Walter, Stewart.... Many thanks to you.  Definitely making so much progress
> here.
>
> All seems to be going really well, but I remain stumped at a critical point
>
> Given the model, I pass from the controller @parent = Parent.object
>
> All of the field_for aspects are working really beautifully.  But in the
> view I need to test for a parent/child value. I know that this code is
> wrong:
>
> <% unless @lenders.state_id_string.blank? %>   ## @lenders is the parent
> model, and only the fields within that model are being returned.  I thought
> that if I define all parent associations in the AR, then the object @lenders
> would be aware..

Is @lenders a single parent or an array?  Presumable an array since it
is plural.  In which case you can't just test state_id_string.
Possibly you need something like @lenders.where(some condition on
state_id_string), assuming that state_id_string is a database field.
Alternatively perhaps you want to use @lenders.each to select and test
them one at a time.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25c85688-b916-4926-bf0e-f2b42f8c98a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment