Class: ActivitiesController

Inherits:
AuthorizedController
  • Object
show all
Defined in:
app/controllers/activities_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



30
31
32
33
34
35
# File 'app/controllers/activities_controller.rb', line 30

def create
  create! {
    params = {:date => @activity.date.in(1.day).to_date, :project_id => @activity.project_id}
    polymorphic_url([:new, parent, :activity].compact, :activity => params)
  }
end

#newObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/activities_controller.rb', line 10

def new
  # Allow callers specifying defaults
  if params[:activity]
    @activity = Activity.new(params[:activity])
  else
    @activity = Activity.new(:date => Date.today)
  end

  # Educated guessing of person
  @activity.person ||= Person.find(params[:employee_id]) if params[:employee_id]
  @activity.person ||= Person.find(params[:person_id]) if params[:person_id]
  @activity.person ||= current_user.person if current_user

  # Educated guessing of project
  @activity.project_id ||= params[:project_id] if params[:project_id]
  @activity.project_id ||= @activity.person.latest_project.try(:id)

  new!
end