Daily Refactor #16: Rename method in RolesController

The Refactoring

I’m continuing last Friday’s refactor today, but this time renaming the method in RolesController.

Before

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# app/controllers/roles_controller.rb
class RolesController  :post, :only => [ :destroy, :move ],
         :redirect_to => { :action => :list }
 
  def index
    list
    render :action => 'list' unless request.xhr?
  end
 
  def list
    @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
    render :action => "list", :layout => false if request.xhr?
  end
 
  # ...
end

After

1
2
3
4
5
6
7
8
9
10
11
# app/controllers/roles_controller.rb
class RolesController  :post, :only => [ :destroy, :move ],
         :redirect_to => { :action => :index }
 
  def index
    @role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
    render :action => "index", :layout => false if request.xhr?
  end
 
  # ...
end

Review

I also applied this refactoring to the other controllers that duplicated the code. The result is the same for each so I’m not going to bother post each one but you can see the changes for the AuthSourcesController and TrackersController on Github. This should remove an entire duplication set in flay and cleanup some older Redmine code.

Reference commit