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

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.