Reputation: 89
I'm trying to use some embedded ruby in the subject line of an email coming from ActionMailer but keep getting different errors.
I couldn't find any documentation on the proper syntax. Any resources to fix this line of code?
mail(to: @user.email, subject: "Your Reservation Confirmation for" + @restaurant.name)
I've passed in all of the variables fine. I just need to see how I can combine text and these inputs.
Thanks
Upvotes: 0
Views: 180
Reputation: 1784
I don't know whether this is intentional, but apparently @restaurant.name
is returning a number (as you clarified, you're getting a TypeError: no implicit conversion of Fixnum into String
). Calling @restaurant.name.to_s
will solve that.
As G.B mentioned in another answer, string interpolation like "...Confirmation for #{@restaurant.name}" works too, since it calls #to_s
for you automatically.
I'm putting the solution into an answer, since we found it while clarifying in the comments.
Upvotes: 1
Reputation: 3721
There are two common ways to it:
First:(regarding rep)
"...Confirmation for" + @restaurant.name.to_s
Second: you can use string interpolation
"...Confirmation for #{@restaurant.name}"
Upvotes: 2