Tutorial "8.5"?

39 views
Skip to first unread message

simple_n00b

unread,
Apr 4, 2011, 5:57:59 PM4/4/11
to Hobo Users
The following is a collection of the techniques to add functionality
and change the default form fields, in the tutorial as it is at the
end of tutorial 8.
Most of this information comes from replies to my posts in this forum.
Below is the summary of how to

1. Add new children from the parent form in a has-many relationship.
2. Use radio buttons rather than the select menu to associate a parent
from the child form.
3. Use checkboxes rather than the select menu in has-many-through

----------------------------------------

1. add new children (recipes) from parent(country)
in parent model (models>country.rb) association declaration add
:accessible => true
like
has_many :recipes, :accessible => true

-----------------------------------------

2. Use radio buttons rather than the select menu to associate a
parent(country) from the child(recipe) form.
In application.dryml add the following:

<!-- radio for a belongs_to -->
<def tag="radio-one" attrs="options,limit">
<% saved_this = this
conditions =
ActiveRecord::Associations::BelongsToAssociation.new(this_parent,
this_field_reflection).conditions if options.nil?
options ||= this_field_reflection.klass.all(:conditions =>
conditions, :limit => limit).select {|x| can_view?(x)}
name = param_name_for_this(true)
%>
<repeat with="&options">
<input type="radio" name="&name"
value="&this.id" checked="&saved_this==this"/><view/><br/>
</repeat>
</def>


<extend tag="form" for ="Recipe">
<old-form merge>
<field-list: fields="title,body,categories,country">
<country-view:>
<radio-one/>
</country-view:>
</field-list:>
</old-form>
</extend>

-------------------------------------------

3. Use checkboxes rather than the select menu in has-many-through
In the above example simply add:
<categories-view:>
<check-many/>
</categories-view:>

This goes right before
radio-one definition, like so

<extend tag="form" for ="Recipe">
<old-form merge>
<field-list: fields="title,body,categories,country">
<categories-view:>
<check-many/>
</categories-view:>
<country-view:>
<radio-one/>
</country-view:>
</field-list:>
</old-form>
</extend>



tonym

unread,
Oct 26, 2012, 5:56:04 AM10/26/12
to hobo...@googlegroups.com
This is all just what I need, but I'm going round in circles trying to figure out why I'm getting an error...

I've tried check-many and radio-one.  Also tried modifying check-many, but with all cases I always get a 'undefined method `conditions' for #<ActiveRecord::Associations::BelongsToAssociation:0x32ee700>'

Tried reproducing with tutorial 8 and get this same error.  Any ideas on fixing this?  Is it a v2pre issue or ruby/rails version related?

Arnaud Doyen

unread,
Oct 26, 2012, 7:18:27 AM10/26/12
to hobo...@googlegroups.com
Hi,

I remember there was a change from rails 3.0 about conditions. You need to get it using options[:conditions] instead of method "conditions".

Then, you should use
ActiveRecord::Associations::BelongsToAssociation.new(this_parent,this_field_reflection).options[:conditions]

Regards,
Arnaud.

2012/10/26 tonym <blymi...@gmail.com>
This is all just what I need, but I'm going round in circles trying to figure out why I'm getting an error...

I've tried check-many and radio-one.  Also tried modifying check-many, but with all cases I always get a 'undefined method `conditions' for #<ActiveRecord::Associations::BelongsToAssociation:0x32ee700>'

Tried reproducing with tutorial 8 and get this same error.  Any ideas on fixing this?  Is it a v2pre issue or ruby/rails version related?

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/UL3q-i8SwkgJ.

To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.

tonym

unread,
Oct 26, 2012, 4:33:15 PM10/26/12
to hobo...@googlegroups.com, ado...@perso.be
Thanks Arnaud,
that works perfectly.
I've got this sorted for my project but Bryan, would be good toget this fix and <radio-one> in to v2.

Anthony.

Bryan Larsen

unread,
Oct 27, 2012, 9:52:43 PM10/27/12
to hobo...@googlegroups.com, ado...@perso.be
Please create a github issue, that way it won't get forgotten.

As for radio-one, that's a good idea. Does somebody want to take a stab at it?

The right way to do it would be to move the guts of select-one into a
helper in hobo_rapid that can be then used by both select-one and
radio-one.

Bryan
> https://groups.google.com/d/msg/hobousers/-/arxlJ1z75N0J.
Reply all
Reply to author
Forward
0 new messages