Rails. Undefined method `scan' for :en:Symbol -


i trying set internationalization in rails app. use article https://lingohub.com/blog/2013/08/internationalization-for-ruby-i18n-gem/

but have error:

failure/error: http_accept_language.scan(/^[a-z]{2}/).first       nomethoderror:        undefined method `scan' :en:symbol 

my aplication controller:

def set_locale   i18n.locale = extract_locale_from_accept_language_header end  private def extract_locale_from_accept_language_header   request.env['http_accept_language'].scan(/^[a-z]{2}/).first end 

what problem?

ruby strings respond #scan, not symbols. try calling #to_s on header value below:

def extract_locale_from_accept_language_header   request.env['http_accept_language'].to_s.scan(/^[a-z]{2}/).first end 

Comments