views:

265

answers:

2

I would like to display a button but in a disabled state,to show the user that they already saved an item.

I currently used something like:

<%= button_to 'Save', :disabled => item.is_saved? %>

The generated html looks like:

<form class="button-to" action="/results/save_item/748?class=buttons&amp;disabled=true" method="post"> 

<div><input type="submit" value="Save">
<input type="hidden" value="+TKyrnA9idfmCkwDycLjHIkSLNou6NMt8R4TI73RezU=" name="authenticity_token">
</div>
</form>

This disables the action by setting the disabled=true option. However, the button is still displayed. Is there a way to show the button in a disabled state if the condition is true?

thanks

+1  A: 
<% if item.is_saved? %>
  <%= button_to 'Save' %>
<% end %>
jpartogi
I would like to have it disabled. In the code you suggested, the button does not appear at all if is_saved? is true.
truthSeekr
On your original code the button is not displayed if is_saved is true. So tell me the criteria that you want please.
jpartogi
Sorry, I guess I wasn't clear enough.I would like to display a button but in a disabled state,toshow the user that they already saved it.Instead, the code I originally posted does not have a button at all.I would like a button but in a disabled state.
truthSeekr
A: 

You have to specify URL first or let it empty. In your case :disabled is a param[:disabled].

<%= button_to 'Save', {}, :disabled => item.is_saved? %>
CLer