Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor: Extract Method

Extracted the logic for saving a new time entry to a new private method.
  • Loading branch information...
commit 03957f499dee1a17843f2a13daaacf90fa1afc84 1 parent b0b9a48
Eric Davis authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 app/controllers/bulk_time_entries_controller.rb
16 app/controllers/bulk_time_entries_controller.rb
View
@@ -35,11 +35,7 @@ def save
render :update do |page|
@time_entries.each_pair do |html_id, entry|
- next unless BulkTimeEntriesController.allowed_project?(entry[:project_id])
- @time_entry = TimeEntry.new(entry)
- @time_entry.hours = nil if @time_entry.hours.blank? or @time_entry.hours <= 0
- @time_entry.project_id = entry[:project_id] # project_id is protected from mass assignment
- @time_entry.user = User.current
+ @time_entry = save_time_entry_from_params(entry)
unless @time_entry.save
page.replace "entry_#{html_id}", :partial => 'time_entry', :object => @time_entry
else
@@ -84,6 +80,16 @@ def load_allowed_projects
Project.allowed_to_condition(User.current, :log_time))
end
+ def save_time_entry_from_params(entry)
+ next unless BulkTimeEntriesController.allowed_project?(entry[:project_id])
+ time_entry = TimeEntry.new(entry)
+ time_entry.hours = nil if time_entry.hours.blank? or time_entry.hours <= 0
+ time_entry.project_id = entry[:project_id] # project_id is protected from mass assignment
+ time_entry.user = User.current
+ time_entry
+ end
+ helper_method :save_time_entry_from_params
+
def self.allowed_project?(project_id)
return User.current.projects.find_by_id(project_id, Project.allowed_to_condition(User.current, :log_time))
end

1 comment on commit 03957f4

Please sign in to comment.
Something went wrong with that request. Please try again.