I am at a loss as to why this is happening. I have the following function:
def as_json(options = {}) json = { :id => id, # ... more unimportant code } unless options[:simple] # ... more unimportant code end json end It works most of the time, but in one particular partial where I call this:
window.JSONdata = <%= @day.to_json.html_safe %> I get the following error:
ActionView::Template::Error (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]):
Pointing to the line "unless options[:simple]". As far as I can tell, the options hash is nil - thus the method is ignoring the default param assignment. WHY? I can fix this by changing the method to:
def as_json(options) options ||= {} json = { :id => id, # ... more unimportant code } unless options[:simple] # ... more unimportant code end json end Does this make any sense to anyone!? Most appreciative for your help.