Ahoy, i''m trying to save a many to many between "talent" and
"vital
stat"
talent_controller.rb
def edit
@talent = Talent.find(params[:id], :include => [:talent_type,
:vital_stats])
@talent_types = TalentType.find_all
@vital_stats = VitalStat.find_all
if request.post?
@talent.attributes = params[:talent]
@talent.attributes = params[:talent_type]
if @talent.update_attributes(params[:vital_stat][:id])
flash[:notice] = ''Talent was successfully updated.''
end
end
end
def delete
Form fields for checkboxes
<fieldset>
<legend>Select Vital Stats</legend>
<% VitalStat.find(:all).each do |g| %>
<%= form_bit_checkbox(''vital_stat'', g.id, g.title,
'''', '''',
@talent.vital_stats.include?(g) ? {''checked'' =>
''checked''} : '''') %>
<% end %>
<div class="cleaner"></div>
</fieldset>
My problem is that the talent isn''t being updated w/ the checked or
unchecked fields. The returned PARAMS could look like this:
commit: Save
action: edit
talent: !map:HashWithIndifferentAccess
title: Casting Director
id: "2"
talent_type: !map:HashWithIndifferentAccess
talent_type_id: "1"
controller: talent
vital_stat: !map:HashWithIndifferentAccess
"2": "0"
"3": "0"
"4": "1"
which means there are three checkboxes, the last being checked - but my
talent always shows all 3 as checked (meaning its not updating the fact
that they are currently unchecked)
Any help?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
sorry for the lot of code, but the question is very simple. Anyone? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> if @talent.update_attributes(params[:vital_stat][:id])Aren''t you missing a .save there? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
doesn''t work either way
Here is the debug of params:
--- !map:HashWithIndifferentAccess
commit: Save
action: edit
talent: !map:HashWithIndifferentAccess
title: Casting Director
id: "2"
talent_type: !map:HashWithIndifferentAccess
talent_type_id: "1"
controller: talent
vital_stat: !map:HashWithIndifferentAccess
"2": "0"
"3": "0"
"4": "1"
^ notice the vital stat ID''s, 0 = not set, 1 = set.
talent debug:
--- &id001 !ruby/object:Talent
attributes:
title: Casting Director
id: "2"
talent_type_id: "1"
errors: !ruby/object:ActiveRecord::Errors
base: *id001
errors: {}
new_record_before_save:
talent_type: !ruby/object:TalentType
attributes:
title: Talent
id: "1"
vital_stats:
- !ruby/object:VitalStat
attributes:
title: Hair Color
id: "2"
- !ruby/object:VitalStat
attributes:
title: Eye Color
id: "3"
- !ruby/object:VitalStat
attributes:
title: Height
id: "4"
Still shows association with all vital stats.
>> if @talent.update_attributes(params[:vital_stat][:id])
>
> Aren''t you missing a .save there?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Serialized attribute saved as HashWithIndifferentAccess in database
- Creating/Saving dependent objects
- typecasting HashWithIndifferentAccess
- Sharing sessions between a rails3 app and a rails2 app. Rails 2 app crashes.
- How to get all selected rows in the mutli-selection listbox?