Further details for: auto_actions_for requested

66 views
Skip to first unread message

ylluminate

unread,
Jun 26, 2011, 10:44:23 AM6/26/11
to Hobo Users
I am attempting to use auto_actions_for within a controller
(property_types_controller.rb) that is supposed to allow for a new and
create within it's child property model. Each time I add this or any
variation of this to the PropertyTypesController:
"auto_actions_for :property, [:new, :create]" I end up getting a
failure in rails with the app simply not starting and the following
output:

Exiting
/Users/username/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/whiny_nil.rb:48:in `method_missing': undefined method
`macro' for nil:NilClass (NoMethodError)
from /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/hobo-1.3.0.RC/lib/
hobo/controller/model.rb:266:in `auto_actions_for'
from /Volumes/localdrive/Users/username/project/app/controllers/
property_types_controller.rb:7:in `<class:PropertyTypesController>'
from /Volumes/almaRAID/Users/username/project/app/controllers/
property_types_controller.rb:1:in `<top (required)>'
--END SNIPPET--

Now, when I pluralize the model to properties in the previous
auto_actions_for line, the app seems to work just fine. In the
examples (in the book and on github) I've seen this model is singular,
whereas this seems to behave better when it is plural. Why is this
behaving as such?

Second, in the Properties creation page it already has existing
Property Types, so it appears that it does not show a "New Property
Type" link nor an inline creation section. Is that because there are
existing types? And if so, how do you force it to show one or the
other or both options to create new "property types" in this scenario?


-George

ylluminate

unread,
Jun 26, 2011, 2:20:13 PM6/26/11
to Hobo Users
Bob, curious, did you ever get this sorted?
http://groups.google.com/group/hobousers/browse_thread/thread/35e85595f8f2086f/baa603cbe427c14e?lnk=gst&q=auto_actions_for#baa603cbe427c14e

It appears that that post here is slightly connected and I see other
use cases of auto_actions_for, however each time it seems that child
models are being manipulated rather than parents. Is this the case?
Is my problem that you must use auto_actions_for from a controller
that is a child model to a parent that is rendering the input form(s)?

If so I'm assuming that I need to rethink things here a bit.

Thanks again guys for any help / enlightenment on this matter.


-George



On Jun 26, 10:44 am, ylluminate <yllumin...@gmail.com> wrote:
> I am attempting to useauto_actions_forwithin a controller
> (property_types_controller.rb) that is supposed to allow for a new and
> create within it's child property model.  Each time I add this or any
> variation of this to the PropertyTypesController:
> "auto_actions_for:property, [:new, :create]" I end up getting a
> failure in rails with the app simply not starting and the following
> output:
>
> Exiting
> /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
> active_support/whiny_nil.rb:48:in `method_missing': undefined method
> `macro' for nil:NilClass (NoMethodError)
>         from /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/hobo-1.3.0.RC/lib/
> hobo/controller/model.rb:266:in `auto_actions_for'
>         from /Volumes/localdrive/Users/username/project/app/controllers/
> property_types_controller.rb:7:in `<class:PropertyTypesController>'
>         from /Volumes/almaRAID/Users/username/project/app/controllers/
> property_types_controller.rb:1:in `<top (required)>'
> --END SNIPPET--
>
> Now, when I pluralize the model to properties in the previousauto_actions_forline, the app seems to work just fine.  In the

Bob Sleys

unread,
Jun 26, 2011, 3:18:04 PM6/26/11
to hobo...@googlegroups.com
Nope never did. My app is still stuck on this point.  I narrowed it down to where the form for tag. It's getting confused with the link to the model via a :through class.  I direct :has_many works fine but a :has_many :though used for a many to many association doesn't work and I haven't figured out a fix.

Matt Jones

unread,
Jun 26, 2011, 5:15:30 PM6/26/11
to hobo...@googlegroups.com

On Jun 26, 2011, at 2:20 PM, ylluminate wrote:

> Bob, curious, did you ever get this sorted?
> http://groups.google.com/group/hobousers/browse_thread/thread/35e85595f8f2086f/baa603cbe427c14e?lnk=gst&q=auto_actions_for#baa603cbe427c14e
>
> It appears that that post here is slightly connected and I see other
> use cases of auto_actions_for, however each time it seems that child
> models are being manipulated rather than parents. Is this the case?
> Is my problem that you must use auto_actions_for from a controller
> that is a child model to a parent that is rendering the input form(s)?
>
> If so I'm assuming that I need to rethink things here a bit.
>
> Thanks again guys for any help / enlightenment on this matter.

I'm guessing you've got a many-to-many between Property and PropertyType; the issue, here as in Bob's case, is that auto_actions_for is somewhat specialized for handling a simpler sort of relation. To be precise, here's the case it's intended for:

class ParentThing
has_many :things
end
class Thing
belongs_to :parent_thing
end

class ThingsController
auto_actions_for :parent_thing, [:index, :new, :create]
end

As you've both noted, trying this on either side of a has_many :through isn't so good.

As to your other question (regarding the selector + new form), you might want to check out Bryan's select-one-or-new-dialog in hobo-jquery; I'm not certain it will do what you've described, but it's certainly a step in the right direction.

--Matt Jones

Bob Sleys

unread,
Jun 26, 2011, 5:44:29 PM6/26/11
to hobo...@googlegroups.com
Thanks for the reply Matt and the confirmation that using an actions_for won't work.

The next question then is can anyone recommend the Hobo way to mimic the auto actions_for.  IE I need to add an add new form to the show page on one side of a many_to_many association for the other side.  IE add an add new form for Model B on the show page for Model A.

Bob

ylluminate

unread,
Jun 26, 2011, 5:59:35 PM6/26/11
to Hobo Users
Matt, thanks for that. Actually in this particular case I do not have
a man-to-many relationship for Property and PropertyType, but I
appreciate your delineation of the precise usage case!

In my case I have:
class ParentThing
has_many :things
children :things #doubt this matters, but thought I'd include it as
it's in play
end
class Thing
belongs_to :parent_thing
end

class ParentController
auto_actions_for :thing, [:index, :new, :create]
end
--END SNIPPET--

So you can see that it is a reversed scenario. In this case I was
hopeful to see the functionalities to add new and create, etc. for the
ParentThing in the Thing's new form, however nothing renders.

Is there something I'm missing or a way to force this to render?


-George



On Jun 26, 5:15 pm, Matt Jones <al2o...@gmail.com> wrote:
> On Jun 26, 2011, at 2:20 PM, ylluminate wrote:
>
> > Bob, curious, did you ever get this sorted?
> >http://groups.google.com/group/hobousers/browse_thread/thread/35e8559...

Bob Sleys

unread,
Jun 26, 2011, 6:27:32 PM6/26/11
to hobo...@googlegroups.com
You have the auto_actions for on the wrong controller

class ThingController 
  auto_actions_for :Parent, [:index, :new, :create] 
end 


I believe what you need is the above.

ylluminate

unread,
Jun 27, 2011, 9:51:37 AM6/27/11
to Hobo Users
Unfortunately no, it appears that this is not the solution in this
scenario.

Let me give the real code here:

#### MODELS ####
class PropertyType < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
# FIELDS
end
has_many :properties
children :properties
end

class Property < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
# FIELDS
end
belongs_to :property_type # <------------ child of PropertyType
belongs_to :user
has_many :property_images, :dependent => :destroy
belongs_to :city
belongs_to :county
belongs_to :township
has_many :rooms
children :property_images, :rooms
end
#### END MODELS ####

So, if I try this in either of the controllers it simply will not
produce any visible results on the properties new page.

Bob Sleys

unread,
Jun 27, 2011, 10:21:22 AM6/27/11
to hobo...@googlegroups.com
Think you might also need an  :accessible => :true on the association

 has_many :properties, :accessible => :true

The auto actions for goes in the child controller pointing back to the parent.  IE you telling hobo to add actions to the parent for the child from the child controller. Note this adds the routes which can be seen via rake routes. You then need to add children line to the parent to have it list all the children on the parent show page if desired and specify the association as accessible. At least that's how I think it works.

Bob

ylluminate

unread,
Jun 27, 2011, 10:38:58 AM6/27/11
to Hobo Users
Your explanation seems sound, however I'm still having no success with
the suggestion.

Matt Jones

unread,
Jun 28, 2011, 9:25:44 AM6/28/11
to hobo...@googlegroups.com

A couple things:

- you definitely want to check out select-one-or-new; this is *exactly* the use case that was designed for.

- auto_actions_for isn't going to do anything relevant here, especially for the new page; it's hard to make a request to /properties/:property_id/property_types/new when :property_id isn't set yet.

The typical usage of auto_actions_for in your scenario would be a somewhat different flow; you'd locate (or create new) a particular PropertyType and then hit a route like /property_types/:property_type_id/properties/new to create a new record with that type.

--Matt Jones

ylluminate

unread,
Jun 28, 2011, 3:15:07 PM6/28/11
to Hobo Users
Matt: THANK YOU! Tremendous. I am curious, I am converting an app
that used to have the following scenario:

There were fields such as "Elementary School" and "Heating System"
where they were simply table attributes and not actual children to a
parent table. The way it worked was that there was a special control
via javascript that was a textfield with a drop down. This control
would query the db so as to pull all, for example, "Cooling System"
entries from all "Cooling System" attributes in the table to populate
the drop down and allow an autofill as the user typed of the correct
entry if one already existed. The reason this is useful is that these
items could change pretty regularly. A modern control that would
currently fit this bill is: http://coffeescripter.com/code/editable-select/
Is this currently possible with Hobo?

Additionally Matt, it seems that the "Hobo way" of adding images to
something is to add a record and then immediately offer back the show
page and then add images or other things with that. Is there a way to
allow images and other such dynamic things (such as in this case I'm
also adding "Rooms" in a dynamic way) on the creation page? I realize
it's a chicken and egg scenario where you don't have the parent record
yet to which to attach them, so I don't know if this has been
considered so as to make tmp records and then reassign them upon
parent record creation...?

Thanks again!

Matt Jones

unread,
Jun 28, 2011, 3:27:50 PM6/28/11
to hobo...@googlegroups.com

On Jun 28, 2011, at 3:15 PM, ylluminate wrote:

> Matt: THANK YOU! Tremendous. I am curious, I am converting an app
> that used to have the following scenario:
>
> There were fields such as "Elementary School" and "Heating System"
> where they were simply table attributes and not actual children to a
> parent table. The way it worked was that there was a special control
> via javascript that was a textfield with a drop down. This control
> would query the db so as to pull all, for example, "Cooling System"
> entries from all "Cooling System" attributes in the table to populate
> the drop down and allow an autofill as the user typed of the correct
> entry if one already existed. The reason this is useful is that these
> items could change pretty regularly. A modern control that would
> currently fit this bill is: http://coffeescripter.com/code/editable-select/
> Is this currently possible with Hobo?
>

Bryan recently added something of the editable-dropdown flavor:

http://groups.google.com/group/hobousers/browse_thread/thread/d3dafe2ab97cac03?hl=en

Not sure if this exactly fits your description, though.

> Additionally Matt, it seems that the "Hobo way" of adding images to
> something is to add a record and then immediately offer back the show
> page and then add images or other things with that. Is there a way to
> allow images and other such dynamic things (such as in this case I'm
> also adding "Rooms" in a dynamic way) on the creation page? I realize
> it's a chicken and egg scenario where you don't have the parent record
> yet to which to attach them, so I don't know if this has been
> considered so as to make tmp records and then reassign them upon
> parent record creation...?

You can create multiple associated records in one go (even on a 'new' record) with input-many and friends. The biggest gotcha with things like that and image upload is that it's always messy to stash images someplace when a record fails validation (and uploading them more than once is terrible UX).

--Matt Jones

kevinpfromnm

unread,
Jun 28, 2011, 3:46:37 PM6/28/11
to hobo...@googlegroups.com
Would be good if there was a simple way to presubmit multipart forms to validate before the full submission (and file upload).  Not sure how you'd be able to do it a generic way.  Maybe a check for a validate_only parameter on hobo_create?  Then just do an ajax call to validate before submitting the full form.

ylluminate

unread,
Jun 28, 2011, 4:51:26 PM6/28/11
to Hobo Users
I was thinking just that too Kevin while reading Matt's post. Seems
like the right approach. I think some ajax method to prevalidate
based on model info is the key.

And yes, I think that the work Bryan did there is perhaps spot on.
Appreciate you pointing that out. Good stuff for complex forms that
need flexibility convenience for data entry folks.
Reply all
Reply to author
Forward
0 new messages