Optional Atrributes for Partials

I just stumbled about a nice and only a little dirty approach to make partial attributes optional.


def options;{};end
def item;nil;end


render :partial=>'xyz', :item=>@user, :options=>{:show_something=>true}
render :partial=>'xyz'

Inside partial

text = options[:show_something] if item

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s