Cameron Cameron - 20 days ago 6
Ruby Question

Pass link back to notice in Rails

In my Rails app I want to pass back link to the notice from the controller.

e.g.

redirect_to permalinks_path, :notice => "Permalinks updated! You will want to update the #{link_to 'Site map', sitemap_path} too!"


However I get an error:

undefined method `link_to' for #<SettingsController:0x007fda280480f8>


How can I solve this?

Answer

You have to use view_context:

redirect_to(
  permalinks_path,
  :notice => "Permalinks updated! You will want to update the #{view_context.link_to 'Site map', sitemap_path} too!"
)

You might also want to add .html_safe to the string.