>From the check-many tag source

<input name='#{param_name}[]' type='hidden' value=''/> # ensures all
items are removed when nothing checked

So for yours, param_name would be "recipe[tag_ids][]"

Side note, for tag in Tag.find(:all) { some code if tag.owner_is?
current_user } is going to be way slower than necessary and harder to
read in dryml since it will grab all tags and then throw out the ones
that aren't owned by right user.  Try:

<repeat with="&current_user.tags">
  <%= check_box_tag "recipe[tag_ids][]", tag.id, @recipe.tags.include?
(tag)  %>
  <%= tag.title %><br/>
</repeat>

And last, you probably can get check-many by passing your options list
to it.

<check-many options="&current_user.tags" />

On Dec 7, 10:54 am, Mark Sobkowicz <[email protected]> wrote:
> I have a Recipe model which has many Tags through tag_assignments.
> Tags also belong to Users.
> On the Recipe show page, I have a form where the user can change tags.   I 
> tried to use <check-many> for this and couldn't get it to work, so my form is:
>
>                                         <section param="tag_form_for_recipe">
>                         <h3> My Tags for <%= @recipe.title %> </h3>
>                                 <% form_for @recipe do %>
>                                         <% for tag in Tag.find(:all) %>
>                                                 <% if tag.owner_is? 
> current_user then %>
>
>                                                         <%= check_box_tag 
> "recipe[tag_ids][]", tag.id, @recipe.tags.include?(tag)  %>
>                                                         <%= tag.title %><br/>
>                                                 <% end %>
>                                         <% end %>
>                                         <%= submit_tag 'Save' %>
>                                 <% end %>
>
>                 </section>
>
> My question is about the hobo_update controller in Recipe.    It works fine, 
> EXCEPT if I uncheck all the tags.   I found a reference online for this 
> problem - it said to put
>
>                                 @recipe.attributes = {'tag_ids' => 
> []}.merge(params[:recipe] || {})
>
> in the controller.   But this would have to go after the find, and before the 
> change parts of the update.  
>
> Is there a way to add this as an option to hobo_update?
>
> I looked at the hobo_update method, and tried tinkering with it.   If I put in
>
>                         def hobo_update(*args, &b)
>                                 options = args.extract_options!
>
>                                  self.this ||= args.first || find_instance
>
>                                 this.attributes = {'tag_ids' => 
> []}.merge(params[:recipe] || {})  #I ADDED THIS LINE
>
>                                 changes = options[:attributes] || 
> attribute_parameters or raise RuntimeError, 
> ht(:"hobo.messages.update.no_attribute_error", :default=>["No update 
> specified in params"])
>
>                                 this.user_update_attributes(current_user, 
> changes)
>
> It still comes up with the error  "No update specified in parmas" - but it 
> also seems to work!   Which doesn't make sense to me since changes should be 
> empty, if the error is raised.
>
> Would I be better off trying to tinker with the form?

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