5 Apr
HOWTO: Call a nil :local variable from a partial
Have you notice that if you try to execute a partial like the following:
# _my_name.rhtml This is a partial and this is my name: <%=name%>
without calling it by a :name locale you are prompted this nice Exception ?
undefined local variable or method `name' for #<#<Class:0x542ae28>:0x542ad24>
The only way to avoid this exception is to execute a line of code that checks if the variable is nil and, in case of positive answer, it set that variable to nil! I know this could sound quite weird but it’s the only way I raise to make thing work.
So, here is the line:
<% # _my_name.rhtml name = name.nil? ? false : name %>
If someone know why this strange behavior happens please let me know.
