0

I am facing the below error after I removed two fields middle_name, last_name from the Student migration thru another migration. below are the errors.

Searchlogic::NamedScopes::OrConditions::UnknownConditionError in StudentController#advanced_search

The condition 'last_name' is not a valid condition, we could not find any scopes that match this.

RAILS_ROOT: /root/ansipro342
Application Trace | Framework Trace | Full Trace

/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:96:in `interpolate_or_conditions'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:75:in `each'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:75:in `interpolate_or_conditions'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:36:in `or_conditions'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:19:in `or_condition?'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:10:in `condition?'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/scopes.rb:10:in `scope?'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/method_missing.rb:16:in `method_missing'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:19:in `send'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:19:in `conditions='
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:15:in `each'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:15:in `conditions='
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/date_parts.rb:19:in `conditions='
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/base.rb:18:in `initialize'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/implementation.rb:10:in `new'
/root/ansipro342/vendor/plugins/searchlogic/lib/searchlogic/search/implementation.rb:10:in `search'
/root/ansipro342/app/controllers/student_controller.rb:816:in `advanced_search'

Request

Parameters:

{"search"=>{"order"=>"", "first_name_or_middle_name_or_last_name_or_admission_no_like"=>"Imran"}, "commit"=>"Search"}

Following is the code area from Student controller where line 816 exists

def advanced_search
    @search = Student.search(params[:search])
    unless params[:search].present?
      @batches = Batch.all
    else
      if params[:search].present?
        @students = Array.new
        if params[:advv_search].present? and params[:advv_search][:course_id].present?
          unless params[:search][:batch_id_equals].present?
            params[:search][:batch_id_in] = Batch.find_all_by_course_id(params[:advv_search][:course_id]).collect{|b|b.id}
          end
        end
        if params[:search][:is_active_equals]=="true"
          @students = Student.ascend_by_first_name.search(params[:search]).paginate(:page => params[:page],:per_page => 30)
        elsif params[:search][:is_active_equals]=="false"
          @students = ArchivedStudent.ascend_by_first_name.search(params[:search]).paginate(:page => params[:page],:per_page => 30)
        else
          @students = [{:student => {:search_options => params[:search], :order => :first_name}},{:archived_student => {:search_options => params[:search], :order => :first_name}}].model_paginate(:page => params[:page],:per_page => 30)#.sort!{|m, n| m.first_name.capitalize <=> n.first_name.capitalize}
        end
        @searched_for = ''
        @searched_for += "<span>#{t('name')}/#{t('admission_no')}: " + params[:search][:first_name_or_admission_no_like].to_s + "</span>" if params[:search][:first_name_or_admission_no_like].present?
        @searched_for += "<span>#{t('name')}: " + params[:search][:first_name_like].to_s + "</span>" if params[:search][:first_name_like].present?
        @searched_for += " <span>#{t('admission_no')}: " + params[:search][:admission_no_equals].to_s + "</span>" if params[:search][:admission_no_equals].present?
        if params[:advv_search].present? and params[:advv_search][:course_id].present?
          course = Course.find(params[:advv_search][:course_id])
          batch = Batch.find(params[:search][:batch_id_equals]) unless (params[:search][:batch_id_equals]).blank?
          @searched_for += "<span>#{t('course_text')}: " + course.full_name + "</span>"
          @searched_for += "<span>#{t('batch')}: " + batch.full_name + "</span>" if batch.present?
        end

Please help I dont know where the last_name exists that its showing in error, I am very new to ruby on rails nd need this importantly.

Thanks in advance.

Naveed
  • 59
  • 2
  • 13
  • you can try `rake db:setup` in your terminal,i think this will help you.according to me this is your migration and database mismatch problem. – Erica Dec 11 '15 at 09:11
  • Thanks for ur reply, it gave me the below error. rake aborted! You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.update_attributes – Naveed Dec 11 '15 at 09:34
  • install Pry gem 'gem pry-rails' to your application. Add 'binding.pry' before line 816 and step through the code. This will give you access to all the variables among other things like calling the methods yourself. – AfDev Dec 11 '15 at 09:40

2 Answers2

0

Thanks for the replies, The problem solved.

The problem was in the index migration, actually I removed the columns from the create migration but it was already there in index migration.

Naveed
  • 59
  • 2
  • 13
0

Dude that code is huge and very unlikely that someone will understand it by reading it one time.. Install rubocop or some other lint tool and clean that mess.

alebian
  • 786
  • 5
  • 17
  • thanks dear but I am learning ruby on rails now and dont know these things yet. – Naveed Dec 11 '15 at 11:49
  • Well you are here to learn I guess.. Gem install rubocop.. Then $ rubocop -R --format simple.. That will tell you all your Ruby lint problems.. You probably want to ignore the documentation and line length (minor to 99) or you can search for a config file that skips those.. – alebian Dec 11 '15 at 11:55
  • Also you can't just copy paste your code here and expect people to read everything... I mean there are people that will do it but it is more likely more people will read it if it is clean and readable – alebian Dec 11 '15 at 11:57