<commit_before>module Effective
  class RegionsController < ApplicationController
    respond_to :html, :json
    layout false

    before_filter :authenticate_user! if defined?(Devise)
    skip_log_page_views :quiet => true, :only => [:snippet] if defined?(EffectiveLogging)

    skip_before_filter :verify_authenticity_token, :only => [:update]

    def edit
      EffectiveRegions.authorized?(self, :edit, Effective::Region.new())

      cookies['effective_regions_editting'] = {:value => params[:exit].presence || request.referrer, :path => '/'}

      # TODO: turn this into a cookie or something better.
      uri =  URI.parse(request.url.sub('/edit', ''))
      uri.query = [uri.query, "edit=true"].compact.join('&')
      redirect_to uri.to_s
    end

    def update
      refresh_page = false
      response = {}

      Effective::Region.transaction do
        (request.fullpath.slice!(0..4) rescue nil) if request.fullpath.to_s.starts_with?('/edit') # This is so the before_save_method can reference the real current page

        region_params.each do |key, vals| # article_section_2_title => {:content => '<p></p>'}
          to_save = nil  # Which object, the regionable, or the region (if global) to save

          regionable, title = find_regionable(key)

          if regionable
            EffectiveRegions.authorized?(self, :update, regionable) # can I update the regionable object?

            region = regionable.regions.find { |region| region.title == title }
            region ||= regionable.regions.build(:title => title)
<commit_msg>Patch the redirect to edit action to handle query parameters<commit_after>module Effective
  class RegionsController < ApplicationController
    respond_to :html, :json
    layout false

    before_filter :authenticate_user! if defined?(Devise)
    skip_log_page_views :quiet => true, :only => [:snippet] if defined?(EffectiveLogging)

    skip_before_filter :verify_authenticity_token, :only => [:update]

    def edit
      EffectiveRegions.authorized?(self, :edit, Effective::Region.new())

      cookies['effective_regions_editting'] = {:value => params[:exit].presence || request.referrer, :path => '/'}

      # TODO: turn this into a cookie or something better.
      uri = URI.parse(Rack::Utils.unescape(request.url.sub('/edit', '')))
      uri.query = [uri.query, "edit=true"].compact.join('&')
      redirect_to uri.to_s
    end

    def update
      refresh_page = false
      response = {}

      Effective::Region.transaction do
        (request.fullpath.slice!(0..4) rescue nil) if request.fullpath.to_s.starts_with?('/edit') # This is so the before_save_method can reference the real current page

        region_params.each do |key, vals| # article_section_2_title => {:content => '<p></p>'}
          to_save = nil  # Which object, the regionable, or the region (if global) to save

          regionable, title = find_regionable(key)

          if regionable
            EffectiveRegions.authorized?(self, :update, regionable) # can I update the regionable object?

            region = regionable.regions.find { |region| region.title == title }
            region ||= regionable.regions.build(:title => title)

{'fraction_non_alphanumeric': 0.11888331242158093, 'fraction_numerical': 0.0018820577164366374, 'mean_word_length': 3.344686648501362, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '7241343', 'n_tokens_mistral': 943, 'n_tokens_neox': 911, 'n_words': 243}