# Problems with flash messages and characters like Ã¼ Ã¶ Ã¤

**URL:** <https://www.ruby-forum.com/t/problems-with-flash-messages-and-characters-like-a-a-a/119209>\
**Category:** Rails\
**Created:** [November 4, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/problems-with-flash-messages-and-characters-like-a-a-a/119209 "2007-11-04T22:49:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumwutdum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@sumwutdum](https://www.ruby-forum.com/u/sumwutdum)\
**Post date:** [November 4, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/problems-with-flash-messages-and-characters-like-a-a-a/119209/1 "2007-11-04T22:49:09Z")

</div>

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](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
