Sha256: 95928bea64ed5f16f2f525866516da39ec010be05d7911455e0336c3bf700ae5

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

class ActivitiesController < AuthorizedController
  belongs_to :project, :optional => true
  belongs_to :person, :optional => true
  belongs_to :employee, :optional => true

  has_scope :by_date
  has_scope :by_period, :using => [:from, :to]
  has_scope :by_project_id

  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

  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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bookyt_projects-1.1.2 app/controllers/activities_controller.rb
bookyt_projects-1.1.1 app/controllers/activities_controller.rb
bookyt_projects-1.1.0 app/controllers/activities_controller.rb
bookyt_projects-1.0.1 app/controllers/activities_controller.rb
bookyt_projects-1.0.0 app/controllers/activities_controller.rb