Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created May 14, 2010 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroos/401180 to your computer and use it in GitHub Desktop.
Save chrisroos/401180 to your computer and use it in GitHub Desktop.
Playing around with moving html from flash messages into helper methods
module FlashHelper
# If message contains symbol like strings we'll inject the value from that helper method
# e.g. 'foo :bar baz' will return 'foo <return value of the bar method> baz'
def render_flash_message(message)
h(message).gsub(/:(flash_\w+)/) { send $1 }
end
def flash_helper_method
'*you called a_helper_method*'
end
def flash_signup_link
link_to 'sign up', new_user_path
end
end
<div>
<%= render_flash_message flash[:message] %>
</div>
<div>
hello world *you called a_helper_method* and a <a href="/users/new">sign up</a> link
</div>
class WemsController < ApplicationController
def index
flash.now[:message] = "hello world :flash_helper_method and a :flash_signup_link link"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment