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.