这不是问题,而是我找到的解决方案。
我正在使用 Ruby on Rails 4.1 开发一个应用程序,该应用程序以西班牙语、英语和日语显示文本。
当我开始功能测试时,我不断收到以下错误:
NoMethodError: nil:NilClass 的未定义方法“扫描”
冲浪我看到几个帖子有同样的错误,但没有一个对我有用。
这是代码原始代码:
application_controller.rb :
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
navegador = extract_locale_from_accept_language_header
ruta = params[:locale] || nil
unless ruta.blank?
I18n.locale = ruta if IDIOMAS.flatten.include? ruta
else
I18n.locale = navegador if IDIOMAS.flatten.include? navegador
end
end
private
def extract_locale_from_accept_language_header
request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
end
def ajusta_pagina_filtro
if defined? params[:post][:filtrar_por]
buscar = params[:post][:filtrar_por]
else
buscar = ''
end
page = params[:pagina] || 1
[page, …Run Code Online (Sandbox Code Playgroud)