Skip to content

Instantly share code, notes, and snippets.

@dangalipo
Created December 2, 2015 00:50
Show Gist options
  • Save dangalipo/e0c0ba972f3658437841 to your computer and use it in GitHub Desktop.
Save dangalipo/e0c0ba972f3658437841 to your computer and use it in GitHub Desktop.
def create
@institution = Institution.new(institution_params.except(:admin), as: :admin)
if @institution.save_with_admin(login: institution_params[:admin]
redirect_to admin_institutions_path, flash: {
success: "Institution created."
}
else
flash.now[:error] = 'Unable to create institution.'
render :new
end
end
def save_with_admin(login: login)
admin = User.find_by_login(login)
if admin.present? || login.nil?
self.admin = admin
save
else
errors.add(:admin_id, "Could not find user with login #{login}")
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment