0

I've been n00bing with some Ruby on Rails and the first thing I wanted to try out was doing an each through an array / hash (I'm a bit confused about the Ruby terms atm).

In test_controller.rb I've got:

class TestController < ApplicationController
  def index

    @People = ['Daniel','Chris','Pål']

  end
end

In test/index.html.erb I've got:

<h1>Test#index</h1>

<ul>
  <% @People.each do |person| %>

    <li><%= person %></li>

  <% end %>
</ul>

This apparently causes an error, and I get the We're sorry, but something went wrong.-message.

But if I change the third element to something without Æ/Ø/Å e.g. "Pal" instead of "Pål", then everything works fine!

Does anyone know why this is happening?

I'm using RubyMine 4.5 with UTF-8

1 Answers1

2

In test_controller.rb put:

# encoding: utf-8

at the very top.

Krule
  • 6,468
  • 3
  • 34
  • 56
  • Wow, thanks that's quick! But do I have to add this to all my controllers? I want this be work as default – user1184756 Nov 29 '12 at 22:58
  • Some links for how to automate this. http://stackoverflow.com/questions/3291017/how-can-i-avoid-putting-the-magic-encoding-comment-on-top-of-every-utf-8-file-in http://stackoverflow.com/questions/4804742/ruby-how-to-add-encoding-utf-8-automatically http://stackoverflow.com/questions/8879237/how-does-the-magic-comment-encoding-utf-8-in-ruby-works – 244an Nov 30 '12 at 01:23
  • Yes, if you are dealing with unicode characters in your code, you have to do it. – Krule Nov 30 '12 at 11:55