我通过另一次迁移从Student迁移中删除了两个字段middle_name,last_name后面临以下错误。以下是错误。
#p> StudentController中的Searchlogic :: NamedScopes :: OrConditions :: UnknownConditionError#advanced_search条件'last_name'不是有效条件,我们找不到与此匹配的任何范围。
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'
请求
参数:
{ “搜索”=> { “顺序”=> “中”, “first_name_or_middle_name_or_last_name_or_admission_no_like”=> “中姆兰”}, “提交”=> “中搜索”}
以下是学生控制器中存在第816行的代码区域
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
请帮助我不知道last_name存在于哪里,它显示错误,我对rails上的ruby非常新,需要这个。
提前致谢。
答案 0 :(得分:0)
感谢回复,问题解决了。
问题在于索引迁移,实际上我从创建迁移中删除了列,但它已经存在于索引迁移中。
答案 1 :(得分:0)
老兄,代码很庞大,不太可能有人通过一次阅读来理解它。 安装rubocop或其他一些棉绒工具并清理那个烂摊子。