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
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
You need to convert it to the res
variable which is an integer to a string:
flash[:notice]="the result is" + res.to_s
I would do it using string interpolation:
flash[:notice] = "the result is #{res}"
Which is better than concatenation (using +
) because:
.to_s
for youSee this SO question for more details and comparison