Kevin, that's great code and it works like a charm -- thank you. I
still have tons to learn about the wonders of ruby.

Oddly enough, even with the primative string concatenation I used in
my example above, when I had an empty field somehow I did not end up
with an extra space in between other fields .... I don't know how, but
it did indeed work that way.

On May 24, 2:01 pm, kevinpfromnm <[email protected]> wrote:
> just do [title,first_name,middle_name,last_name,suffix].delete_if { |
> i| i.blank? }.join(' ')
>
> you could replace the delete_if with compact if blank values are nil
> instead of ''
>
> On May 24, 11:38 am, Jeremy Savoy <[email protected]> wrote:
>
>
>
>
>
> > Thanks Matt, that's great to know.
>
> > So, in the very simplest manner I've put this into my model:
>
> > def name
> >         title + " " + first_name + " " + middle_name + " " + last_name + "
> > " + suffix
> > end
>
> > This works pretty good .... of course when I have an empty field (like
> > middle name for instance) then I end up with one extra " " per
> > "name" ... so I'll need to add some conditionals to this.
>
> > thanks again.
> > --jeremy
>
> > On May 24, 12:46 pm, Matt Jones <[email protected]> wrote:
>
> > > On Mon, May 24, 2010 at 12:38 PM, Jeremy Savoy <[email protected]> 
> > > wrote:
> > > > I have a "contact" model that stores the title, first name, middle
> > > > name, last name, and suffix of each contact in separate fields. This
> > > > is done for sorting contacts by any of those values as well as
> > > > statistics (male vs female, etc).
>
> > > > I would like to have a controller action that combines these five
> > > > fields into a meta-field called "name" that could then be used just
> > > > like any other field in my "contacts" model, i.e. in table-plus, the
> > > > view page of each contact, or wherever I see the need.
>
> > > For display purposes, simply defining a method 'name' on the model
> > > that combines them should work; Hobo will pretty much work with
> > > anything in a fields-list call that is a method.
>
> > > --Matt Jones
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Hobo Users" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to 
> > > [email protected].
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/hobousers?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Hobo Users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/hobousers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/hobousers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to