Skip to content

Instantly share code, notes, and snippets.

@scottharvey
Created May 26, 2013 08:50
Show Gist options
  • Save scottharvey/5652126 to your computer and use it in GitHub Desktop.
Save scottharvey/5652126 to your computer and use it in GitHub Desktop.
Example of an update action when using the Reform gem
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
@apotonick
Copy link

We could think about adding an automatic save in an AR form.

@sadjow
Copy link

sadjow commented Dec 10, 2013

@scottharvey @apotonick

I'd do llike that:

class ProjectForm < Reform::Form
  #... properties
  def save
    super
    model.transaction do
      model.save
      model.project.save
    end
  end
end

And call only one atomic save :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment