Daily Refactor #67: Pull Up Method to ApplicationController

The Refactoring

After a two hour Developer Meeting for Redmine this morning, I’m too drained to tackle the entire refactoring for #find_optional_project. I did use pull up method to remove the duplication in the GanttsController and IssuesController though.

Before

1
2
3
4
5
6
7
# app/controllers/issues_controller.rb
class IssuesController  params[:controller], :action => params[:action]}, @project, :global => true)
    allowed ? true : deny_access
  rescue ActiveRecord::RecordNotFound
    render_404
  end
end
1
2
3
4
5
6
7
# app/controllers/gantts_controller.rb
class GanttsController  params[:controller], :action => params[:action]}, @project, :global => true)
    allowed ? true : deny_access
  rescue ActiveRecord::RecordNotFound
    render_404
  end
end
1
2
3
4
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  # ...
end

After

1
2
3
4
# app/controllers/issues_controller.rb
class IssuesController < ApplicationController
  # ...
end
1
2
3
4
# app/controllers/gantts_controller.rb
class GanttsController < ApplicationController
  # ...
end
1
2
3
4
5
6
7
# app/controllers/application_controller.rb
class ApplicationController  params[:controller], :action => params[:action]}, @project, :global => true)
    allowed ? true : deny_access
  rescue ActiveRecord::RecordNotFound
    render_404
  end
end

Review

This finishes up my refactoring of the GanttsController. I’m leaving the refactoring of the other duplicated #find_optional_project methods for another time.

Reference commit

Share

  • Facebook
  • Twitter
  • HackerNews
  • Reddit
  • Tumblr
  • Delicious
  • Email
  • RSS

Related posts:

  1. Redmine Refactor #91: Pull Up set_flash_from_bulk_issue_save to ApplicationController
  2. Redmine Refactor #90: Pull Up Method to ApplicationController
  3. Daily Refactor #66: Pull Up Method to ApplicationController
  4. Daily Refactor #36: Extract Method to the Member model
  5. Daily Refactor #35: Pull up method for finding a controller’s model object

About Eric Davis

I founded Little Stream Software where I provide Redmine and ChiliProject services to help projects teams. I also created an ebook, Redmine Tips, were I show you how to become more productive using Redmine. I am also the author of Refactoring Redmine, where I go about refactoring Rails using Redmine as an example.

, , ,

Chirk HR     Reuse your existing job applicants »
WP Socializer Aakash Web