Skip to content

Instantly share code, notes, and snippets.

@janxious
Created February 10, 2010 16:22
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 janxious/300490 to your computer and use it in GitHub Desktop.
Save janxious/300490 to your computer and use it in GitHub Desktop.
# 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