Rails - disable option in select (based on the condition)

helper, ruby-on-rails, select

Solution

Haven't tested this but in your controller could you not do

@checkvar = @category.id == 18 ? true : false

then in the view

f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => @checkvar})

or in the model write a function to test

def disable_select 
    if self.id == 18
        true
    else 
       false
    end
end

then in the view

f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => @category.disable_select})

Problem

I have select: ``` = f.select(:category_id, @categories, :html_options => {:class => 'select_box'}, {:disabled => true if category.id == 18}) ``` The piece of code above obviously returns an error, but how to disable an option according by `id`?

Original source