Created
May 14, 2010 14:04
-
-
Save chrisroos/401180 to your computer and use it in GitHub Desktop.
Playing around with moving html from flash messages into helper methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<%= render_flash_message flash[:message] %> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
hello world *you called a_helper_method* and a <a href="/users/new">sign up</a> link | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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