【问题标题】:ActionView::Template::Error: undefined method `split' for nil:NilClassActionView::Template::Error: nil:NilClass 的未定义方法`split'
【发布时间】:2016-02-25 16:38:00
【问题描述】:

我正在接受上述错误。我找不到解决方案。请告诉我。

这是我的 feed_view_mobile.erb 代码;

if params[:controller]=='categories'
    meta :title => " #{feed_hash[:filter_keyword]+' | ' if feed_hash[:filter_keyword].present?} " + (feed_hash[:seo_title]||feed_hash[:title]) + ( ((' - Page ' + params[:page]) if params[:page].present?) ||''),
    :description => " #{feed_hash[:filter_keyword]+' | ' if feed_hash[:filter_keyword].present?} " + (feed_hash[:description] || '') + ( ((' - Page ' + params[:page]) if params[:page].present?) ||''),
    :keywords => (feed_hash[:filter_keyword].split.select{ |x| x.length>2}).concat(feed_hash[:keywords] || feed_hash[:title].split.select{ |x| x.length >2 })
    #salwar special case for testing.
    @secondary_message = "<a class='btn btn-primary btn-attn' href='"+new_user_registration_path.to_s+"'>Signup </a>" + "  and get your free personal stylist." if !current_user.present? && params[:term]!="salwars-churidars"
    @secondary_message = ""
end

【问题讨论】:

  • 当然,你没有发现你的错误,你的视图代码太复杂了。要开始简化它,请创建辅助方法。

标签: ruby-on-rails ruby


【解决方案1】:

feed[:filter_keyword] 或 filter[:title] 似乎都是 nil。

检查您如何设置这些值或使用方法 try 处理它们可能为零的情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多