Created
February 10, 2010 16:22
-
-
Save janxious/300490 to your computer and use it in GitHub Desktop.
This file contains 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
# Code review | |
# | |
# This seems really verbose...seems that there should be a simpler way to conditionally set | |
# the value of a variable. I would like to write something like: | |
# body = post.get_formatted_body || "" | |
# | |
# That fails when the post is nil. This helper has to deal with a nil post object being passed in | |
# so I added the .nil? check. This is a contrived version of the situation I have, so don't | |
# nitpick the details. | |
# | |
# Is there a simpler way to handle assignment like this...failing over to a value if something is nil? | |
# text_area_tag will take nils, so you don't have to set it to something explicitly | |
# Check out andand: http://andand.rubyforge.org/ | |
def body_tag(post=nil) | |
body = post.andand.get_formatted_body | |
text_area_tag 'post', body | |
end | |
# or this | |
def body_tag(post=nil) | |
body = post ? post.get_formatted_body : nil | |
text_area_tag 'post', body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment