Here's what I've done ... 1) I just added the specific fields I want to search on to the list, :first_name, :middle_name, :last_name ... this works great.
2) For default sort order by last name I didn't realized that the scope I was trying didn't provide that feature, but I found this which works great: set_default_order "last_name asc" On May 25, 12:53 pm, kevinpfromnm <[email protected]> wrote: > you've got a couple choices. > 1) you can denormalize and add the name as a real db column (there are > several downsides to doing this) > 2) you could use a full text indexer for searches like solr or ferret > which can index based off any method (probably the best if you're > going to want full text search anywhere in the app) > 3) you can manually make the search/sort scopes > > On May 25, 7:05 am, Jeremy Savoy <[email protected]> wrote: > > > > > > > So this all works pretty good, I can use "this" in my table plus and > > it puts the fully generated "name" field into the table just as you > > would hope. > > > I'm having trouble now setting scopes on the index action. This is > > what I'd like to use: > > > def index > > hobo_index Contact.apply_scopes(:search => > > [params[:search], :name], > > :order_by => > > parse_sort_param(:last_name)) > > end > > > There are two problems though: > > > 1) First, when I try to search I'm told that contacts.name doesn't > > exist. If I change it to :last_name or :first_name etc, the search > > works on those fields. > > > 2) Second, the sort does not work, my table-plus is still ordered by > > contact_id (:id). > > > Any ideas? > > > thanks, > > Jeremy > > > On May 24, 3:06 pm, kevinpfromnm <[email protected]> wrote: > > > > actually, that's the wonders of html. more than one whitespace > > > character in a row is treated as one > > > > On May 24, 12:37 pm, Jeremy Savoy <[email protected]> wrote: > > > > > 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 > > > > 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 > 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.
