RubyOnRails, ActiveScaffold

228 Views Asked by At

I work with active scaffold

Table has many data so pagination is actually for this case.

In table printed data about companies if I check one - so we see in table only this one. User's checking - saved in session variable.

Occasionally after I go to other page suddenly i see data about other company.

Seems that session was lost or changed

May anyone had same problem.

class TLForConfirmController < ApplicationController
    layout 'application'
    before_action :update_as_config
    active_scaffold :tl do |config|
      #config.sti_children = :tl_change
      FIRST_PART_COLUMNS=   [:id_org_by_year,:organization_name, :start_date,:end_date]
      SECOND_PART_FIRST_HALF_COLUMNS=[:tl_short_type_first_half,:main_subject_first_half,:day_of_week_first_half]
      SECOND_PART_SECOND_HALF_COLUMNS=[:tl_short_type,:main_subject,:day_of_week]

      config.list.per_page = 100

      config.columns[:id_org_by_year].set_link(link_for_association(config.columns[:tl_changes]))
    end

    def self.reflect_on_all_associations
        TL.reflect_on_all_associations
    end

    def  conditions_for_collection // here attached session[:act_organization] to question
        sql_filter=''
        if  !session[:tl_status].blank? and session[:tl_status].to_s.to_i!=Activity::STATUS_DELETED and  session[:act_id].to_i==0
          sql_filter=' activity_status_id in ('+ session[:tl_status].join(',')+ ')'
        end
        # logger.info "    check session ----------> " + session[:act_organization].inspect
        if !session[:act_organization].blank? and session[:act_organization][0]>0 
            unless sql_filter.empty?
              sql_filter=sql_filter+' and '
            end
            sql_filter=sql_filter+'organization_id in ( '+(Array session[:act_organization]).to_a.join(',')+ ')'
        end
        unless sql_filter.empty?
            ['('+sql_filter+')']
        end
    end
end

list_to_confirm.html.erb:

<%if @sql_filter.empty?%>
<%= render :active_scaffold => 'tl_for_confirm',
:params => {:file_time => Time.now.strftime("%Y%m%d%H%M%S")},:locals => {:file_time1 => Time.now.strftime("%Y%m%d%H%M%S")} %>
<%else%>
<%= render :active_scaffold => 'tl_for_confirm', :conditions => @sql_filter , :params => {:file_time => Time.now.strftime("%Y%m%d%H%M%S")} %>
<% end %>

Controller: tl_controller.rb

TLController< ApplicationController
    def search_results // here code sends after Submit for define sesions
        if request.post?

        if !params[:search][:organization_id].blank?
            session[:act_organization]=get_array_codes_for_search(params[:search][:organization_id].to_a.collect { |item| item.to_i })
            logger.info " search_results " + session[:act_organization].inspect
        else
            session[:act_organization]=nil
        end
        end
    end

    def  list_to_confirm
    end

end

def get_array_codes_for_search(arr_code)
    rez=[]

     unless arr_code.blank?
      if arr_code[0].kind_of?(Array)
        arr_code = arr_code[0] 
      end
      if arr_code.kind_of?(String)  
        arr_code = (Array arr_code) 
      end

      unless arr_code.size==0
          arr_code.delete_if{|c| c.to_i<=0||c.to_s.empty? }
          res = arr_code.map{|i| i.to_i}
      end
     end
   return res

end

PS

  1. I check log file: its indeed sudenly "take" other value for company.
  2. At controller in action any same value(number)
  3. So there is 2-files with config:
    • session_store.rb : Rails.application.config.session_store :active_record_store, :key => '_my_app_session'
    • new_framework_defaults.rb:

This file contains migration options to ease your Rails 5.0 upgrade.

Read the Rails 5.0 release notes for more info on each option.

Enable per-form CSRF tokens. Previous versions had false.

Rails.application.config.action_controller.per_form_csrf_tokens = true

Enable origin-checking CSRF mitigation. Previous versions had false. Rails.application.config.action_controller.forgery_protection_origin_check = true

Make Ruby 2.4 preserve the timezone of the receiver when calling to_time. Previous versions had false.

ActiveSupport.to_time_preserves_timezone = true

Require belongs_to associations by default. Previous versions had false.

Rails.application.config.active_record.belongs_to_required_by_default = true

Do not halt callback chains when a callback returns false. Previous versions had true.

ActiveSupport.halt_callback_chains_on_return_false = false

Configure SSL options to enable HSTS with subdomains. Previous versions had false.

Rails.application.config.ssl_options = { hsts: { subdomains: true } }
0

There are 0 best solutions below