Created
          May 26, 2013 08:50 
        
      - 
      
- 
        Save scottharvey/5652126 to your computer and use it in GitHub Desktop. 
    Example of an update action when using the Reform gem
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def update | |
| @form = ProjectForm.new project: project | |
| if @form.validate(params[:project]) && @form.save && @form.project.save | |
| redirect_to edit_admin_project_path(project) | |
| else | |
| render :edit | |
| end | |
| end | 
I'd do llike that:
class ProjectForm < Reform::Form
  #... properties
  def save
    super
    model.transaction do
      model.save
      model.project.save
    end
  end
endAnd call only one atomic save :)
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
We could think about adding an automatic save in an AR form.