Reputation: 19294
I'm trying to disable a dropdown from being updated on a form.
Currently i have this line in my form:
<%= f.select :permission, options_for_select([['Admin', 'admin'], ['Read Only', 'readonly'], ['Editable', 'editable']], {:disabled => @permissions_disabled}) %>
With my edit controller method containing:
@permissions_disabled = params[:id].to_i == current_user.id.to_i
p @permissions_disabled
I can clearly see in my log that 1@permissions_disabled1 is true, but when i edit the form, i can still select new values in the dropdown.
What am i doing wrong here?
Upvotes: 1
Views: 4532
Reputation: 29599
select
accepts 5 parameters, the 4th one is a set of options for the helper. the 5th one is the html options like class and id. I think you need to pass it to that
<%= f.select :permission, options_for_select([['Admin', 'admin'], ['Read Only', 'readonly'], ['Editable', 'editable']], {}, {:disabled => @permissions_disabled}) %>
UPDATE: didn't see the options_for_select
in your code. you don't need that if you're using select
, you'd only want to use that when you're using select_tag
<%= f.select :permission, [['admin', 'Admin'], ['readonly', 'Read Only'], ['editable', 'Editable']], {}, {:disabled => @permissions_disabled} %>
Upvotes: 8