class ProjectsController < ApplicationController
  def new
    @user = current_user
    @project = Project.new
  end

  def create
    @user = current_user
    @project = @user.projects.build(project_params)
    if @project.save
      redirect_to root_path
    else
      flash.now[:error] = "Learn how to type ... if you want to be a writer."
      render 'projects/_new'
    end
  end

  def edit
    @user = current_user
    @project = @user.projects.last
    @goal_field = @project.check_goal_type
    render :edit
  end

  def update
    @user = current_user
    @project = Project.find(params[:id])
    @project.update_attributes(project_params)
    @pace_needed = @project.calculate_pace

    # @project = current_user.get_project
    @words_left = @project.num_words_to_goal
    @time_left = @project.time_until_deadline
    # @pace_unit = @project.pace_unit
    @pace_needed = @project.calculate_pace.floor

    render json: [@words_left, @time_left, @pace_needed]
  end

  def destroy
    @project = current_user.projects.last
    @project.destroy
    redirect_to root_path
  end

  private
    def project_params
      params.require(:project).permit(:title, :wordcount_goal, :goal_time_limit, :goal_deadline_date, :user_id, :current_wordcount)
    end
end
class ProjectsController < ApplicationController
  def new
    @user = current_user
    @project = Project.new
  end

  def create
    @user = current_user
    @project = @user.projects.build(project_params)
    if @project.save
      redirect_to root_path
    else
      flash.now[:error] = "Learn how to type ... if you want to be a writer."
      render 'projects/_new'
    end
  end

  def edit
    @user = current_user
    @project = @user.projects.last
    @goal_field = @project.check_goal_type
    render :edit
  end

  def update
    @user = current_user
    @project = Project.find(params[:id])
    @project.update_attributes(project_params)
    @pace_needed = @project.calculate_pace

    @words_left = @project.num_words_to_goal
    @time_left = @project.time_until_deadline
    @pace_needed = @project.calculate_pace.floor

    render json: [@words_left, @time_left, @pace_needed]
  end

  def destroy
    @project = current_user.projects.last
    @project.destroy
    redirect_to root_path
  end

  private
    def project_params
      params.require(:project).permit(:title, :wordcount_goal, :goal_time_limit, :goal_deadline_date, :user_id, :current_wordcount)
    end
end
Remove commented-out lines from projects controller update action.
Remove commented-out lines from projects controller update action.
