ActionView::Template::Error (undefined method `strip!' for nil:NilClass)
当我插入超过 100,000 条记录时,我似乎遇到了这个错误。我知道它可以支持的远不止这些。错误如下和相关类的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 2015-07-01 08:14:24.512:INFO:/:Started GET"/search?type=digital_object" for 129.118.15.44 at 2015-07-01 08:14:24 -0500| 2015-07-01 08:14:24.512:INFO:/:Processing by SearchController#search as HTML| 2015-07-01 08:14:24.512:INFO:/: Parameters: {"type"=>"digital_object"}| Jul 01, 2015 8:14:24 AM org.apache.solr.core.SolrCore execute INFO: [collection1] webapp= path=/select params={facet=true&sort=title_sort+asc&facet.limit=100&qf=four_part_id^3+title^2+finding_aid_filing_title^2+fullrecord&wt=json&rows=10&defType=edismax&pf=four_part_id^4&start=0&q=*:*&facet.field=repository&facet.field=primary_type&facet.field=subjects&facet.field=source&facet.field=linked_agent_roles&fq=types:("digital_object")&fq=-exclude_by_default:true&fq=publish:true} hits=203799 status=0 QTime=15 2015-07-01 08:14:24.590:INFO:/: Rendered G:/archivesspace/plugins/vva/public/views/search/_components_switch.html.erb (15.0ms)| 2015-07-01 08:14:24.590:INFO:/: Rendered search/_filter.html.erb (0.0ms)| 2015-07-01 08:14:24.606:INFO:/: Rendered search/_pagination_summary.html.erb (16.0ms)| 2015-07-01 08:14:24.637:INFO:/: Rendered search/_inline_results.html.erb (47.0ms)| 2015-07-01 08:14:24.637:INFO:/: Rendered search/results.html.erb within layouts/application (62.0ms)| 2015-07-01 08:14:24.653:INFO:/:Completed 500 Internal Server Error in 141.0ms| 2015-07-01 08:14:24.653:INFO:/:|ActionView::Template::Error (undefined method `strip!' for nil:NilClass):| 17: <% elsif result["primary_type"] ==="repository" %>| 18: <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %>| 19: <% else %>| 20: <%= link_to title_or_finding_aid_filing_title( result ) , :controller => :records, :action => result["primary_type"], :id => id, :repo_id => repo_id %>| 21: <% end %>| 22: | 23: | app/helpers/application_helper.rb:22:in `title_or_finding_aid_filing_title'| app/views/search/_inline_results.html.erb:20:in `_app_views_search__inline_results_html_erb___996910774_15116'| app/views/search/_inline_results.html.erb:5:in `_app_views_search__inline_results_html_erb___996910774_15116'| app/helpers/application_helper.rb:134:in `render_aspace_partial'| app/views/search/results.html.erb:13:in `_app_views_search_results_html_erb__332589766_15048'| app/controllers/search_controller.rb:21:in `search'| app/controllers/search_controller.rb:20:in `search'||| |
_inline_results.html.erb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <% if search_data.results? %> <%= render_aspace_partial :partial =>"search/pagination_summary", :locals => {:search_data => search_data} %> <ul class="results-list"> <% search_data['results'].each do |result| %> <% id = JSONModel(result["primary_type"]).id_for(result['uri']) repo_id = JSONModel(:repository).id_for(JSONModel.repository_for(result['uri']),{}, true) %> <li class="result"> <%= icon_for result["primary_type"] %> <% if result["primary_type"] ==="subject" %> <%= link_to result["title"], {"filter_term" => search_data.facet_query_string("subjects", result["title"])} %> <% elsif ["agent_person","agent_software","agent_family","agent_corporate_entity"].include?(result["primary_type"]) %> <%= link_to result['title'], :controller => :records, :action => :agent, :id => id, :agent_type => result["primary_type"] %> <% elsif result["primary_type"] ==="repository" %> <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> <% else %> <%= link_to title_or_finding_aid_filing_title( result ) , :controller => :records, :action => result["primary_type"], :id => id, :repo_id => repo_id %> <% end %> <%= render_aspace_partial :partial =>"search/result_summary_#{result["primary_type"]}", :locals => {:obj => result} %> </li> <% end %> </ul> <%= render_aspace_partial :partial =>"search/pagination", :locals => {:search_data => search_data} %> <% else %> <p class="alert alert-info"> <%= I18n.t("search_results.no_results") %>. </p> <% end %> |
search_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | require 'advanced_query_builder' class SearchController < ApplicationController DETAIL_TYPES = ['accession', 'resource', 'archival_object', 'digital_object', 'digital_object_component', 'classification', 'agent_person', 'agent_family', 'agent_software', 'agent_corporate_entity'] VIEWABLE_TYPES = ['agent', 'repository', 'subject'] + DETAIL_TYPES FACETS = ["repository","primary_type","subjects","source","linked_agent_roles"] def search set_search_criteria @search_data = Search.all(@criteria, @repositories) @term_map = params[:term_map] ? ASUtils.json_parse(params[:term_map]) : {} respond_to do |format| format.html { render"search/results" } format.js { render_aspace_partial :partial =>"search/inline_results", :content_type =>"text/html", :locals => {:search_data => @search_data} } end end def advanced_search set_advanced_search_criteria @search_data = Search.all(@criteria, @repositories) render"search/results" end def repository set_search_criteria if params[:repo_id].blank? @search_data = Search.all(@criteria.merge({"facet[]" => [],"type[]" => ["repository"]}), {}) return render"search/results" end @repository = @repositories.select{|repo| JSONModel(:repository).id_for(repo.uri).to_s === params[:repo_id]}.first @breadcrumbs = [ [@repository['repo_code'], url_for(:controller => :search, :action => :repository, :id => @repository.id),"repository"] ] @search_data = Search.repo(@repository.id, @criteria, @repositories) render"search/results" end private def set_search_criteria @criteria = params.select{|k,v| ["page","q","type","sort", "filter_term","root_record","format"].include?(k) and not v.blank? } @criteria["page"] ||= 1 @criteria["sort"] ="title_sort asc" unless @criteria["sort"] or @criteria["q"] or params["advanced"].present? if @criteria["filter_term"] @criteria["filter_term[]"] = Array(@criteria["filter_term"]).reject{|v| v.blank?} @criteria.delete("filter_term") end if params[:type].blank? @criteria['type[]'] = DETAIL_TYPES else @criteria['type[]'] = Array(params[:type]).keep_if {|t| VIEWABLE_TYPES.include?(t)} @criteria.delete("type") end @criteria['exclude[]'] = params[:exclude] if not params[:exclude].blank? @criteria['facet[]'] = FACETS end def set_advanced_search_criteria set_search_criteria terms = (0..2).collect{|i| term = search_term(i) if term and term["op"] ==="NOT" term["op"] ="AND" term["negated"] = true end term }.compact if not terms.empty? @criteria["aq"] = AdvancedQueryBuilder.new(terms, :public).build_query.to_json @criteria['facet[]'] = FACETS end end def search_term(i) if not params["v#{i}"].blank? {"field" => params["f#{i}"],"value" => params["v#{i}"],"op" => params["op#{i}"],"type" =>"text" } end end end |
application_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | module ApplicationHelper def include_theme_css css ="" css += stylesheet_link_tag("themes/#{ArchivesSpacePublic::Application.config.public_theme}/bootstrap", :media =>"all") css += stylesheet_link_tag("themes/#{ArchivesSpacePublic::Application.config.public_theme}/application", :media =>"all") css.html_safe end def set_title(title) @title = title end def title_or_finding_aid_filing_title(resource) if resource["finding_aid_filing_title"] && !resource["finding_aid_filing_title"].nil? && resource["finding_aid_filing_title"].length > 0 title = resource["finding_aid_filing_title"] elsif resource["title"] && !resource["title"].nil? title = resource["title"] else title = resource["display_string"] end MixedContentParser::parse(title, url_for(:root)) end def icon_for(type) "<span class='icon-#{type}' title='#{I18n.t("#{type}._singular")}'></span>".html_safe end def label_and_value(label, value) return if value.blank? label = content_tag(:dt, label) value = content_tag(:dd, value) label + value end def i18n_enum(jsonmodel_type, property, value) return if value.blank? property_defn = JSONModel(jsonmodel_type).schema["properties"][property] return if property_defn.nil? if property_defn.has_key?"dynamic_enum" enum_key = property_defn["dynamic_enum"] #return"enumerations.#{enum_key}.#{value}" I18n.t("enumerations.#{enum_key}.#{value}", :default => value) else I18n.t("#{jsonmodel_type}.#{property}_#{value}", :default => value) end end def params_for_search(opts = {}) search_params = { :controller => :search, :action => :search } search_params["filter_term"] = Array(opts["filter_term"] || params["filter_term"]).clone search_params["filter_term"].concat(Array(opts["add_filter_term"])) if opts["add_filter_term"] search_params["filter_term"] = search_params["filter_term"].reject{|f| Array(opts["remove_filter_term"]).include?(f)} if opts["remove_filter_term"] search_params["sort"] = opts["sort"] || params["sort"] search_params["q"] = opts["q"] || params["q"] search_params["format"] = params["format"] search_params["root_record"] = params["root_record"] search_params["agent_type"] = params["agent_type"] search_params["page"] = opts["page"] || params["page"] || 1 if opts["type"] && opts["type"].kind_of?(Array) search_params["type"] = opts["type"] else search_params["type"] = opts["type"] || params["type"] end search_params["term_map"] = params["term_map"] # retain any advanced search params advanced = (opts["advanced"] || params["advanced"]) search_params["advanced"] = advanced.blank? || advanced === 'false' ? false : true search_params[:action] = :advanced_search if search_params["advanced"] (0..2).each do |i| search_params["v#{i}"] = params["v#{i}"] search_params["f#{i}"] = params["f#{i}"] search_params["op#{i}"] = params["op#{i}"] end search_params.reject{|k,v| k.blank? or v.blank?} end def set_title_for_search title = I18n.t("actions.search") if @search_data if params[:type] && !@search_data.types.blank? title ="#{I18n.t("search_results.searching")} #{@search_data.types.join(",")}" end facets_to_display = [] if @search_data.query? facets_to_display << @search_data.facet_label_for_query end if @search_data.filtered_terms? facets_to_display << @search_data[:criteria]["filter_term[]"].collect{|filter_term| @search_data.facet_label_for_filter(filter_term)} end if facets_to_display.length > 0 title +=" | #{facets_to_display.join(",")}" end end set_title(title) end def truncate(string, length = 50, trailing = '…') return string if string.length < length "#{string[0..50]}#{trailing}".html_safe end # See: ApplicationController#render_aspace_partial def render_aspace_partial(args) defaults = {:formats => [:html], :handlers => [:erb]} return render(defaults.merge(args)) end def proxy_localhost? AppConfig[:frontend_proxy_url] =~ /localhost/ end end |
我明白了。看起来一些导入的数据有空白标题"。通过更新它们,它能够工作。
错误在你的 _inline_results.html.erb...
1 2 | <% elsif result["primary_type"] ==="repository" %> <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> |
错误是结果['title'] 为 nil。所以,添加这行代码....
1 2 3 4 | <% elsif result["primary_type"] ==="repository" %> <% if !result['title'].blank? %> <%= link_to result['title'], :controller => :search, :action => :repository, :repo_id => id %> <% end %> |