# File app/controllers/tasks_controller.rb, line 21
  def create
    if params[:task] && params[:task][:period_id] && params[:task][:period_id][0..0] == 'G'
      detour_to :controller => 'periods', :action => :new, :group_id => params[:task][:period_id][1..-1].to_i
      return
    end

    file = params[:task].delete(:file)
    
    @task = Task.new(params[:task])
    if @task.save
      flash[:notice] = 'Task was successfully created.'
      if file && file.is_a?(File)
        @task.task_files.create! :name => file.original_filename, :content_data => file.read, :content_type => file.content_type
      end
      @task.move_to_top
      if @task.period
        back_or_redirect_to :controller => 'periods', :action => 'show', :id => @task.period, :task => @task.id
      else
        back_or_redirect_to :controller => 'backlogs', :action => :edit, :id => @task.backlog, :task => @task.id
      end
    else
      populate_layout
      @backlogs = Backlog.find(:all, :order => 'name')
      @periods = Period.find_active_or_future
      render :action => 'new'
    end
  end