Guest User

Untitled

a guest
Jun 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. # in works controller i want to change the action_required attribute
  2. # of a related medium, depending on whether the checkbox value
  3. # :action_required_done (no attribute, just a check_box_tag) is set
  4.  
  5. # params are [:work][:medium_attributes] from a nested form
  6. # [:medium_attributes] has something called :action_required
  7.  
  8. def update
  9. @work = Work.find(params[:id])
  10.  
  11. respond_to do |format|
  12. # does what i want
  13. if params[:action_required_done]
  14. @work.medium.update_attribute(:action_required, false)
  15. end
  16. # alas this resets :action_required to the submitted data
  17. if @work.update_attributes(params[:work])
  18.  
  19. # how do i avoid the second update?
Add Comment
Please, Sign In to add comment