1
我执行在控制器中search
方法,和我不断收到此错误:获取加载ActiveModel一个:: ForbiddenAttributesError在控制器
ActiveModel::ForbiddenAttributesError in TripsController#search
Extracted source (around line #22):
的违规行为以下块中:
if params[:search].present?
@trips = Trip.where("destination LIKE :destination", {:destination=> "%#{params[:search].first}%"}).where(@filters)
else
@trips = (Trip.where(@filters)) rescue (Trip.where(@filters).paginate(:page => params[:page], :per_page => 10))
end
以下是完整的方法代码:
def search
@languages = Trip.pluck(:language).uniq
@interests = Trip.pluck(:interests).uniq
@destinations = Trip.pluck(:destination).uniq
@filters = params.slice(:language,:interests)
@search_param = params[:search].first rescue nil
@language_param = params[:language]
@intersts_param = params[:interests]
if params[:search].present?
@trips = Trip.where("destination LIKE :destination", {:destination=> "%#{params[:search].first}%"}).where(@filters)
else
@trips = (Trip.where(@filters)) rescue (Trip.where(@filters).paginate(:page => params[:page], :per_page => 10))
end
end
非常感谢:)我真的很感谢你的帮助 –