<\/script>')

Rails application helper did not support chinese characters

  def top_cateogries_with_home(category_id=-1)
    concat(raw "<select name='category_id' id='category_id'>")
    container=[]
    for category in Category.top
      container.push([category.name,category.id])
    end
    concat(raw "<option value='-1' selected>首页</option>")
    concat(raw options_for_select(container, selected = nil))
    concat(raw "</select>")
  end

I will write a helper method application_helper.rb, but this will cause a problem if the container symbol of China is 首页, if I replace them with a number or another symbol, this is normal.

I can use a comment with a Chinese character, but if I want to use in the helper, it throws an error, also in the database, chinse data can display with well,

hope someone can help me, thanks

+3
source share
1 answer

Try adding a magical comment # coding: utf-8to the beginning of yourapplication_helper.rb

This is necessary if you are using Ruby 1.9. You can also add it to all files..rb

+6

Source: https://habr.com/ru/post/1773505/


All Articles