Problems with flash messages and characters like ü ö ä

Hello,

Maybe somebody in here can help me. I’m developing an application with
different language support. I use globalize-rails
(http://www.globalize-rails.org) and as i’m from Switzerland i use de-CH
as default language.

Of course de-CH has special characters like ü, ö, ä.

My problem is now that when i use special characters in the flash
variable i get some strange errors back. But only in the flash[:notice]
string and not in the flash[:error] string.

The error happens at following point:
flash[:notice] = “Das Produkt wurde erfolgreich über!”.t

When i take the ü out of the string then it works.

The strange thing is that the ü in the second flash string does not
produce a problem:

flash[:error] = “Das Produkt konnte nicht angelegt über werden!”.t

This is a really strange error and it turns me round the bend since 2
days.

It would be great if somebody could give me some hints where the problem
could be located.

Thanks for your help.

Here the error message:
C:/INSTAN~2/rails_apps/bonuspoints/app/controllers/admin_controller.rb:18:
syntax error, unexpected tCONSTANT, expecting kEND
flash[:error] = “Das Produkt konnte nicht
hinzugef�gt werden!”.t
^
C:/INSTAN~2/rails_apps/bonuspoints/app/controllers/admin_controller.rb:26:
syntax error, unexpected tIDENTIFIER, expecting kEND
administrator = Administrator.find(:first, :conditions =>
[“username = BINARY ? AND password = BINARY ?”,
^
C:/INSTAN~2/rails_apps/bonuspoints/app/controllers/admin_controller.rb:26:
syntax error, unexpected tIDENTIFIER, expecting kDO or ‘{’ or ‘(’
administrator = Administrator.find(:first, :conditions =>
[“username = BINARY ? AND password = BINARY ?”,
^
C:/INSTAN~2/rails_apps/bonuspoints/app/controllers/admin_controller.rb:27:
syntax error, unexpected ‘]’, expecting kEND
params[:administrator][:username],
params[:administrator][:password]])
^
C:/INSTAN~2/rails_apps/bonuspoints/app/controllers/admin_controller.rb:71:
syntax error, unexpected $end, expecting kEND

Here the admin controller

class AdminController < ApplicationController
before_filter :authenticate_administrator, :except => [:login]

# Pick a unique cookie name to distinguish our session data from

others’
session :session_key => ‘_bonuspoints_admin_session_id’

def new_product
    @product = Product.new
    if request.post?
        params[:product]['picture_data'] =

@params[:file][:content].read
params[:product][‘picture_name’] =
@params[:file][:content].original_filename.chomp
params[:product][‘picture_content_type’] =
@params[:file][:content].content_type.chomp
@product = Product.new(params[:product])
if @product.save
flash[:notice] = “Das Produkt wurde erfolgreich
hinzugefügt!”.t
redirect_to :action => ‘list_product’
else
flash[:error] = “Das Produkt konnte nicht hinzugefügt
werden!”.t
render :action => ‘new_product’
end
end
end

def login
    if request.post?
        administrator = Administrator.find(:first, :conditions =>

[“username = BINARY ? AND password = BINARY ?”,
params[:administrator][:username],
params[:administrator][:password]])
if administrator
session[:administrator] = administrator
redirect_to :controller => ‘admin’, :action =>
‘stats_overview’
else
flash[:error] = “Die Anmeldung ist fehlgeschlagen!”
render :action => ‘login’
end
end
end

def logout
    session[:administrator] = nil
    flash[:notice] = "Sie haben sich erfolgreich abgemeldet!"
    redirect_to :action => 'login'
end

protected
def authenticate_administrator
    unless session[:administrator]
        flash[:error] = "Sie sind zur Zeit nicht angemeldet!"
        redirect_to :controller => 'admin', :action => 'login'
    end
end

def stream_csv
    filename = params[:action] + ".csv"

    #this is required if you want this to work with IE
    if request.env['HTTP_USER_AGENT'] =~ /msie/i
        headers['Pragma'] = 'cache'
        headers["Content-type"] = "text/plain"
        headers['Cache-Control'] = 'private'
        headers['Content-Disposition'] = "attachment;

filename="#{filename}""
headers[‘Expires’] = “0”
else
headers[“Content-Type”] ||= ‘text/csv’
headers[“Content-Disposition”] = “attachment;
filename=”#{filename}""
end

    render :text => Proc.new { |response, output|
    csv = FasterCSV.new(output, :col_sep => ";", :row_sep => "\r\n")
    yield csv }
end

end

Here the application controller:

Filters added to this controller apply to all controllers in the

application.

Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
before_filter :set_charset, :set_locale

model :cart

def set_charset
    content_type = headers["Content-Type"] || "text/html"
    if /^text\//.match(content_type)
        headers["Content-Type"] = "#{content_type}; charset=utf-8"
    end
    #content_type = headers["Content-Type"] || "text/html"
    #if /^text\//.match(content_type)
    #    headers["Content-Type"] = "#{content_type};

charset=iso-8859-1"
#end
end

def set_locale
    #Locale.set 'de-CH'
    if !params[:locale].nil? &&

LOCALES.keys.include?(params[:locale])
Locale.set LOCALES[params[:locale]]
else
redirect_to params.merge( ‘locale’ =>
Locale.base_language.code )
end
end

protected
def authenticate
    unless session[:user]
        flash[:error] = "Sie sind zur Zeit nicht angemeldet!".t
        redirect_to :controller => 'user', :action => 'login'
    end
end

# used for calculating the points of the user
def calculate_user_points
    if session[:user]
        @debited_transactions = Accounttransaction.find(:all,

:conditions => “user_id=’#{session[:user][:id]}’”)
@pending_transactions = Accounttransaction.find(:all,
:conditions => “user_id=’#{session[:user][:id]}’ and
pending_status=‘P’”)
@accepted_transactions = Accounttransaction.find(:all,
:conditions => “user_id=’#{session[:user][:id]}’ and
pending_status=‘A’”)
@declined_transactions = Accounttransaction.find(:all,
:conditions => “user_id=’#{session[:user][:id]}’ and
pending_status=‘D’”)

        @total_point_credit =

count_point_credit(@accepted_transactions)
@total_point_debit =
count_point_debit(@debited_transactions)
@total_point_pending =
count_point_credit(@pending_transactions)
@total_point_declined =
count_point_credit(@declined_transactions)
end
end

# used to count total points
def count_point_credit(records)
    total_credit = 0
    records.each do |r|
        total_credit += r.points_credited.to_i
    end
    return total_credit
end

def count_point_debit(records)
    total_debit = 0
    records.each do |r|
        total_debit += r.points_debited.to_i
    end
    return total_debit
end

end