Helpers Outside Views in Rails 5

In this article, we will the changes required to get the original railscast on using helpers outside views working in Rails 5. Here is the create action in products controller:

  def create
    @product =
      flash[:notice] = "Successfully created product #{view_context.link_to('product', @product)}."
      redirect_to @product
      render :new

Use html_safe in the application.html.erb.

<%- flash.each do |name, msg| -%>
  <%= content_tag :div, msg.html_safe, :id => "flash_#{name}" %>
<%- end -%>

You will now see the link to the product in the flash message. You can download the source code from

Related Articles