Ooh - I'm pretty new to hobo, but I just solved this problem (visual
identification by uniquely naming something where no individual field
is unique)...
There is a "name" attribute for fields, so you can pick one field as
the name to be used (there's also rules for picking fields called
"name", "title", etc, by default):
fields do
first, :string, :name => true
second, :string
...
You can't pick two or more fields like this - you get only one field
treated as the name. Try this instead:
def name
"#{name}, #{address1}, #{city}, #{state}"
end
The method "name" will be used to calculate the value to show in
Forms, Cards and Pages. Works a treat for me. :)
I think this is the first answer I've given on this list, rather than
yet another newbie question. Feel my smugnitude (yes, I think this is
actually the right answer).
Cheers, JeremyC.
On Jan 17, 2:58 am, Arthur Baldwin <[email protected]> wrote:
> The solution was to change the contents of contact.rb to the following:
>
> class Contact < ActiveRecord::Base
>
> hobo_model # Don't put anything above this
>
> fields do
> name :string, :required
> company :string
> address_1 :string
> address_2 :string
> city :string
> state :string
> date_met :date
> married :boolean
> age :integer
> notes :text
> timestamps
> end
>
> validates_uniqueness_of :name, :scope => [:address_1, :city, :state]
>
> # --- Permissions --- #
>
> def create_permitted?
> acting_user.administrator?
> end
>
> def update_permitted?
> acting_user.administrator?
> end
>
> def destroy_permitted?
> acting_user.administrator?
> end
>
> def view_permitted?(field)
> true
> end
>
> end
>
> I did not take the time to add the ZipCode field or address_2, but you get
> the idea. The scope adds more fields to the name field to determine whether
> the record has enough "uniqueness". For any company with a large number of
> customers nation wide, this sort of thing is required. Works exactly like I
> had hoped. I tried entering "John Smith" for two separate records, with
> slightly different addresses, and it saved both records. Now I want to find
> a way to visually distinguish easily between those two records from the first
> "Contact" page. In other words, create a calculated field that concatenates
> the name field, address_1, city, state, and ZipCode so that I know
> immediately which "John Smith" to click on.
>
> Sincerely,
>
> Arthur Baldwin
>
> ________________________________
> From: Arthur Baldwin <[email protected]>
> To: "[email protected]" <[email protected]>
> Sent: Monday, January 16, 2012 1:11 PM
> Subject: Re: [Hobo Users] Re: Multi - Field Uniqueness
>
> Ok, I got it working! I had forgotten to include a colon in front of the
> field names between the opening and closing brackets.
>
> Arthur
>
> ________________________________
> From: Arthur Baldwin <[email protected]>
> To: "[email protected]" <[email protected]>
> Sent: Monday, January 16, 2012 12:24 PM
> Subject: Re: [Hobo Users] Re: Multi - Field Uniqueness
>
> What do you mean when you say "fall back to the rails validation"? Do I need
> to make changes to a different file than the conact.rb file in the models
> directory?
>
> Arthur
>
> ________________________________
> From: kevinpfromnm <[email protected]>
> To: [email protected]
> Cc: Arthur Baldwin <[email protected]>
> Sent: Monday, January 16, 2012 12:03 PMco
> Subject: [Hobo Users] Re: Multi - Field Uniqueness
>
> you'll need to fall back to the rails validation (which the hobo is a rails
> validation, just a shortcut for a common use case).
>
> IIRC, the syntax is like validates_uniqueness_of :field, :scope =>
> [:other_field1,...]
>
> If that's not enough to get you going, you can get to the rails docs pretty
> easy with a quick google search on validates_uniquess_of (should autocomplete
> after the u)
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web
> visithttps://groups.google.com/d/msg/hobousers/-/VvjxOt3xpyAJ.
> 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.