<commit_before>class IssuesController < ApplicationController

  # Allows for json post requests to process without the need for a CSRF
  protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }

  def show
    if @issue = Issue.find_by(id: params[:id])

      @categories = @issue.categories

      p @categories

      if @categories.empty?

        @category_name = "Uncategorized"

      end

      @fixes = @issue.fixes
      @comments = @issue.issue_comments.map { |comment| comment.package_info }


      @current_user_watching = false
      @current_user = nil

      if user_signed_in?
        @current_user_id = current_user.id
        @current_user = current_user
        if current_user.issues_watches.where(issue_id: @issue.id).size != 0
          @current_user_watching = true
        end

        @current_user_id = current_user.id
      end

      @upvotes = @issue.users_votes.size

      @current_user_upvoted = false
      if user_signed_in?
        if UsersVote.where(issue_id: @issue.id, user_id: @current_user.id).size != 0
          @current_user_upvoted = true
        end
        @current_user_id = current_user.id
      end


    else
      redirect_to welcome_index_path
    end
  end

  def new
    @categories = Category.all
    return @zip = current_user.zip if user_signed_in?
    redirect_to welcome_index_path
  end

  def create
    category_id_array = []
    uncategorized_category = Category.where(name: "Uncategorized").first

    if params[:categories]
      params[:categories].each do |category_id|
        category_id_array << category_id[1].to_i
      end
    end

    @issue = Issue.new(issue_params)
    @issue.image_url = upload_image if contains_image?

    if @issue.save
      unless category_id_array.empty?
        category_id_array.each do |category_id|
          category = Category.find(category_id)
          category.issues << @issue
        end
      else
        uncategorized_category.issues << @issue
      end
    end

    @issue.update_attributes(user_id: current_user.id)

    # publish event to redis server, sent to dashboard
    Redis.current.publish 'issue-created', Issue.package_latest_issue.to_json
    # publish change to streaming front-page
    Redis.current.publish 'stream', Issue.package_stream_issues.to_json

    redirect_to issue_path(@issue)
  end


  private
  def issue_params
    params.require(:issue).permit(:title, :description, :latitude, :longitude)
  end

end
<commit_msg>Change redirects from welcome_index_path to root_path This looks cleaner as the URL shows '/' rather than '/welcome/index'<commit_after>class IssuesController < ApplicationController

  # Allows for json post requests to process without the need for a CSRF
  protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }

  def show
    if @issue = Issue.find_by(id: params[:id])

      @categories = @issue.categories

      p @categories

      if @categories.empty?

        @category_name = "Uncategorized"

      end

      @fixes = @issue.fixes
      @comments = @issue.issue_comments.map { |comment| comment.package_info }


      @current_user_watching = false
      @current_user = nil

      if user_signed_in?
        @current_user_id = current_user.id
        @current_user = current_user
        if current_user.issues_watches.where(issue_id: @issue.id).size != 0
          @current_user_watching = true
        end

        @current_user_id = current_user.id
      end

      @upvotes = @issue.users_votes.size

      @current_user_upvoted = false
      if user_signed_in?
        if UsersVote.where(issue_id: @issue.id, user_id: @current_user.id).size != 0
          @current_user_upvoted = true
        end
        @current_user_id = current_user.id
      end


    else
      redirect_to root_path
    end
  end

  def new
    @categories = Category.all
    return @zip = current_user.zip if user_signed_in?
    redirect_to root_path
  end

  def create
    category_id_array = []
    uncategorized_category = Category.where(name: "Uncategorized").first

    if params[:categories]
      params[:categories].each do |category_id|
        category_id_array << category_id[1].to_i
      end
    end

    @issue = Issue.new(issue_params)
    @issue.image_url = upload_image if contains_image?

    if @issue.save
      unless category_id_array.empty?
        category_id_array.each do |category_id|
          category = Category.find(category_id)
          category.issues << @issue
        end
      else
        uncategorized_category.issues << @issue
      end
    end

    @issue.update_attributes(user_id: current_user.id)

    # publish event to redis server, sent to dashboard
    Redis.current.publish 'issue-created', Issue.package_latest_issue.to_json
    # publish change to streaming front-page
    Redis.current.publish 'stream', Issue.package_stream_issues.to_json

    redirect_to issue_path(@issue)
  end


  private
  def issue_params
    params.require(:issue).permit(:title, :description, :latitude, :longitude)
  end

end

{'fraction_non_alphanumeric': 0.08331699666732013, 'fraction_numerical': 0.001176239952950402, 'mean_word_length': 2.8245877061469264, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3087311', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1555, 'n_words': 357}