Displaying 1 result from an estimated 1 matches for "b_attr".
Did you mean:
__attr
2006 Feb 19
0
Handling nil attributes in views
...that was not clear - gimme a
minute:-). There has been some discussion of this on the wiki, but I was
wondering what others thought about handling this.
I have class A that belongs_to class B, and I want to display an
attribute of B in the view, so I do something like the following:
<%= A.B.b_attr || "Value not available" %>
B is an optional attribute, i.e., it is not required to be set, so this
throws an exception under those circumstances.
Option 1:
<%= A.B.b_attr rescue "Value not available" %>
Option 2:
Define the reader for B_attr
alias old_b_attr b_a...