I have a form which accepts URL params (to support a bookmarklet) which looks and works like this:
<%= f.url_field :url, :value => params[:u] %>
However, when re-rendered (in case of a validation error, for instance, the content is stripped out.
What I’d like to do is put something like this, so that :value => is only rendered if there are params in the first place:
<%= f.url_field :url, :value => params[:u] if params[:u] %>
Of course this doesn’t even render the field and is wrong.
How do I add if/unless conditionals into an ERB block? Endless searching hasn’t turned up much, but I’m probably searching for the wrong thing.
Farnoy’s answer was very close, but more specifically it was:
As
@resourcewas the model object.