Created
December 2, 2015 00:50
-
-
Save dangalipo/e0c0ba972f3658437841 to your computer and use it in GitHub Desktop.
This file contains 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 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 |
This file contains 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 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