[Rails 3.2.3 / Ruby 1.9.3 I18n.locale :fr .. => accentuated
characters => need UTF-8)

It's very annoying that I need to place an ' # encoding: utf-8' at
the beginning of most of my Rails script files ...
I can understand when using strings w accentuated characters in yaml
files, but I just found another scenario in which I also had to insert
it at the beginning of a model script file ...

I have a Partner model :

class Partner < ActiveRecord::Base
belongs_to :area
attr_accessor :location
validates :location, :location => { :unless => Proc.new { |p|
p.location.blank? } }

with a LocationValidator ( validating the location with Google via
the Geocoder gem .. )
during my tests I placed a puts command to check the value before
calling the GeoCoder.. as this value is auto-generated w Faker gem
class LocationValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
puts "location: #{value}"
results = Geocoder.search(value)

running the test , I got a warning in the console
../.rvm/gems/ruby-1.9.3-p125@rails32/gems/activesupport-3.2.3/lib/active_support/multibyte/chars.rb:59: warning: regexp match /.../n against to UTF-8 string
location: 62, Chemin Albrecht Altdorfer ,72120 ,Évaillé ,France

I inserted ' # encoding: utf-8' in my location validator
script ... wo any change , so
I inserted also ' # encoding: utf-8' in my Partner model script et
voilà, the warning doesn't display in the console....

It seems that we need to place ' # encoding: utf-8' everywhere
when using UTF-8 .... which is the default ...
I have in my environment.rb
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"

and in my application.rb
config.encoding = "utf-8"

Is there any clear recommendation when using UTF-8 that could avoid me
to insert ' # encoding: utf-8' everywhere ?

feedback welcome

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouprubyonrails-talk @
postedMay 11, '12 at 9:53a
activeMay 11, '12 at 3:23p

1 user in discussion

Erwin: 2 posts



site design / logo © 2022 Grokbase