I'm trying to do this:
headline = 'Created a new' && link_to('Set', set_path(set))
Also tried:
headline = 'Created a new' + link_to('Set', set_path(set))
but it does't output like:
Created a new <a href="xxxx">Set</a>
Ideas? thxs
Rails has a nifty XSS prevention feature that might be getting in your way here. Before outputting strings, it will encode any HTML found in them by default, unless they were explicitly marked as safe strings ahead of time. link_to runs html_safe! on its output, which is why it isn't usually encoded, but adding it to an unsafe string like 'Created a new' removes that HTML-safe attribute.
Try calling:
headline.html_safe!
immediately after setting it.
Of course, since the question doesn't specify what output you get instead of what you want, I can't be totally sure that this is the issue. But it's the best I can do with what I've got :)
+ is correct. && is used for boolean expressions, e.g. obj.something_is_true? && obj.somthing_else_is_true?, whereas + will concatenate two strings :)