I am using button_to and link_to form helpers in Rails. I need to set an html attribute based on a condition in code. More precisely, I need to disable a button_to component only if a certain condition is true.
How can I achieve that? code snippet below.
<%= button_to "Submit", "#", :id=> "submit", :class => "button_white_big", :disabled => true%>
In above statement I may need :disabled=>true or I may not need it.
Is there a clean way, apart from duplicating the code line?
Cheers
-Priyank
You can replace the “true” in the disabled with the condition (really any expression that returns a boolean) to get the functionality you need. Like this:
or
etc.