Flash messages are generally composed in the controller. Sometimes we need those flash messages to have links in them (like an undo button).How would you compose such a message?The only sane way I have found to create such messages is by a presenter that includes much of ActionView in it (in order to gain access to most of the view helpers).Right now the code in the controller looks like this:def publish  @post.publish!  flash[:notice] = Post <a href=\/posts/#{@post.id}\>#{@post.title}</a>  +    was published successfully  redirect_to @postendand in the view I do a <%= raw flash[:notice] %> to display it.
HTML flash messages
ruby;ruby on rails;mvc
You actually have several options. One way to clean this up a bit would be to use Rails' I18n module, e.g.:# config/locales/en.ymlen:  post_successful_html: Post <a href=%{url}>%{title}</a> was                        published successfully.# the `_html` suffix marks the string as HTML-safe automaticallyThen in your controller:flash[:notice] = t :post_successful_html, :url   => post_path( @post ),                                          :title => @post.titleAnd the view:<%= flash[:notice] %>(You could also do this the other way around and just put :post_successful_html in flash and then call t flash[:notice], :url => ... in the view but that feels messier to me.) Using I18n for just one thing seems a little like overkill but it is nice and clean (and if you've ever considered localizing your your app it's never too early to start).An alternative is to break what you need out into a partial, e.g. _post_successful_flash.html.erb:Post <%= link_to post.title, post %> was published successfully.And then in your controller:flash[:notice] = render_to_string :partial => 'post_successful_flash',                                  :object  => @post, :as => :postFinally, you could do it in a helper instead:module PostsHelper  def render_post_successful post    Post #{link_to post.title, post} was published successfully.  endendThen in the controller:flash[:notice] = :post_successfulAnd the view:<%= render_post_successful @post if flash[:notice] == :post_successful %>Which one you should use is sort of a toss-up to me. I'm fond of the I18n approach but partly because I prefer to keep messages like this in locales anyway. Use whatever makes the most sense to you.