0

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'.

4
  • Never used heroku. But what are your server's and client's encodings from postgres? You can run these commands "show server_encoding; show client_encoding;" Commented Aug 26, 2012 at 4:46
  • 1
    Another thing to check: make sure you have this line '# encoding: utf-8' at the top of each file which has special characters hardcoded. Commented Aug 26, 2012 at 4:55
  • Where can I run these commands like 'show server_encoding'? Commented Aug 26, 2012 at 10:43
  • I tried to set encoding in different places! But nothing changed. To save 'äüöé...' in other fields in the heroku database is not the problem. Only when I used the select_tag I got this weird problem. My options look like <option value="Tèèst">Tèèst</option>. Maybe there is a problem with special characters in the value attribute of my option tag?? Commented Aug 26, 2012 at 10:47

1 Answer 1

1

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!!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.