What I wish to do is to have a construct like this in a view:
<%= link_to_if <some test>, "New Model View", new_model_path -%>
<some test> has to return true if new_model_path is defined and false
otherwise. What is the proper idiom to do this in rails 2?
I guess you could do:
<% if respond_to?(:new_model_path) %>
<%= link_to ... %>
<% end %>
but that seems very brittle to me. By the time you're writing a view,
you should know what helper methods and named routes exist, and which
ones don't.
but that seems very brittle to me. By the time you're writing a view,
you should know what helper methods and named routes exist, and which
ones don't.
Yes and I do/will. But for the moment I am writing one side of a
bilaterally symmetrical application tree. I therefor wish to make this
functionality dynamic since I am frequently adding and deleting that
specific branch. It is not intended for production code.
In order to call the link_to_if method, its arguments must first be evaluated.
With David's change to
link_to(...) if defined? new_vendor_path
the arguments to the link_to() are only evaluated after the "defined? new_vendor_path" has returned true.