Last active
December 16, 2015 21:09
-
-
Save aaronjensen/5497545 to your computer and use it in GitHub Desktop.
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 create_very_rails | |
project = Project.create project_params | |
if project.persisted? | |
sync_new project | |
redirect_to project | |
else | |
redirect_to edit_project_path(project) | |
end | |
end | |
def create_rails | |
project = portfolio.add_project project_params | |
if project.persisted? | |
sync_new project | |
redirect_to project | |
else | |
redirect_to edit_project_path(project) | |
end | |
end | |
def create_respond_with | |
portfolio.subscribe ProjectSync.new(self) | |
self.project = portfolio.add_project(project_params) | |
respond_with project | |
end | |
def create_on | |
portfolio.on :project_added do |project| | |
sync_new project | |
redirect_to project | |
end | |
portfolio.on :project_add_failed do |project| | |
redirect_to edit_project_path(project) | |
end | |
portfolio.add_project project_params | |
end | |
def create_on_block | |
portfolio.add_project project_params do |on| | |
on.project_added do |project| | |
sync_new project | |
redirect_to project | |
end | |
on.project_add_failed do |project| | |
redirect_to edit_project_path(project) | |
end | |
end | |
end | |
def create_subscribe | |
portfolio.subscribe self, on: %i[project_added project_add_failed] | |
portfolio.add_project project_params | |
end | |
def project_added(project: nil, portfolio: nil) | |
sync_new project | |
redirect_to project | |
end | |
def project_add_failed(project: nil, portfolio: nil) | |
redirect_to edit_project_path(project) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use something similar to
create_on
, but I also likecreate_on_block
since it puts the code in sequential order. Is it possible to callsync_new
within an object other than a controller?