Simon Franzen
Simon Franzen

Reputation: 2727

ruby on rails - heroku postgres - encoding

I have a weird encoding problem or I do it simple the wrong way. Maybe someone have an idea what happens. Info: I'm new to ruby on rails!

I have an array of landscape names and they have special characters like 'äüöéèà...'. In my form I want the user to choose multiple items of these landscapes. So I started with an select_tag with all landscape names:

<%= select_tag 'model[landscapes][]', options_for_select(AVAILABLE_LANDSCAPES, @landscapes_selected), { :multiple => true, :size =>5, :id => "model_landscapes" } %>

In my model I save these names in the database and all works fine. I allready have a big database with these special characters in the landscape string. Existing landscape entries are given as 'ländscape1, lândscape2, blalilü'. I don't have problems with saving or getting data from the databse. On my local machine with a mysql database this works fine! But when I run my application on heroku I have an encoding problem. When I save a string with an char like 'â', it it saved with '\xC3\xA2'.

Upvotes: 0

Views: 421

Answers (1)

Simon Franzen
Simon Franzen

Reputation: 2727

I don't know why this problems only appears when I running my app on heroku!

But, this works for me:

My mistake was that I saved the selected landscapes as a string in my db!

serialize :landscapes

saves und loads my landscapes as an array and then I have no encoding problems!!!

Upvotes: 1

Related Questions