[英]undefined method `gsub' for nil:NilClass (NoMethodError
[英]NoMethodError: undefined method `gsub' for nil:NilClass
我在思考的獅身人面像搜索中添加了條件選項,現在得到了NoMethodError: undefined method `gsub' for nil:NilClass
@users = User.search(params[:search].gsub(/\s+/, ' | '),
:geo => [current_user.latitude * Math::PI / 180.0, current_user.longitude * Math::PI / 180.0],
:with => {:geodist => 0.0..100_000.0},
:conditions => {:ethnicity => params[:ethnicity], :religion => params[:religion]},
:order => 'geodist ASC', :without => {:user_id => current_user.id})
end
render 'users/index', layout: 'new_application'
end
params[:search].gsub(/\s+/, ' | ')
如果params [:search]為nil,則將出錯。 請確保它們是一個值,或者將其提取到另一個名為UserSearcher的類中,該類負責處理此業務邏輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.