On Fri, Jan 9, 2009 at 7:52 PM, kevinpfromnm <[email protected]> wrote:

>
> Easy way is to make a name method that creates what you want for your
> identifier though for a select many you can make your own set of
> options too.
>

I had to create both a name method and a find_by_name method.  A bit hackish
but it works.


Here's everything I tried:


1) Just add a name field

  fields do
    name       :string
  end

works but the model doesn't make sense.  It really doesn't have a name and
generating one seems problematic.


2) Have a path field but declare that to be the name.  I thought this would
work.

  fields do
    path       :string, :name => true
  end

 => undefined method `name' for #<Clip:0xb60de5c4>


3) As suggested, define a name method.

  fields do
    path       :string
  end

  def name
    path
  end

=> undefined method `find_by_name' for #<Class:0xb63d1b50>


4) Stub out both name and find_by_name

  fields do
    path       :string
  end

  def name
    path
  end
  def self.find_by_name(*args)
    find_by_path(args)
  end

Works!


I'd love to hear if there's a better way of doing this.  Thanks kevinp.

    - Scott




>
> On Jan 9, 7:35 pm, "Scott Bronson" <[email protected]> wrote:
> > It appears yes, if you use <select-many>.  I didn't realize I was.  :)
> >
> >     "To use this tag, the model of the items the user is chosing *must*
> have
> > unique names, and the"
> >
> > Not sure what the other requirement is.
> >
> > Presumably <select-many> uses the name like a primary key...  Is there an
> > easy way to the same thing as <select-many> but for models that don't
> have a
> > name field?
> >
> >     - Scott
> >
> > On Fri, Jan 9, 2009 at 4:20 PM, Scott Bronson <[email protected]>
> wrote:
> > > From Hobo::Model:
> >
> > >     def named(*args)
> > >       raise NoNameError, "Model #{name} has no name attribute"
> > > unless name_attribute
> > >       send("find_by_#{name_attribute}", *args)
> > >     end
> >
> > > My application dies in this function because, it's true, my model has
> > > no name.  It doesn't need one!
> >
> > > Adding a useless 'name' field doesn't seem like the right solution,
> > > especially since it appears that Hobo requires the name to be unique.
> >
> > > Is there a good way of solving this?
> >
> > >    - Scott
> >
>

--~--~---------~--~----~------------~-------~--~----~
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