Search code examples
ruby-on-railsrubyflashnotice

For rails app, how to make flash[:notice] to show a complex sentence?


I want to do something like this:

in controller:

res=1+3
if ...
flash[:notice]="the result is" + res
end

However, I found that it does not work, and the error message is like this:

no implicit conversion of Fixnum into String

Solution

  • You need to convert it to the res variable which is an integer to a string:

    flash[:notice]="the result is" + res.to_s