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>