Hellboy
Hellboy

Reputation: 1239

simple_fields in Rails

I have a simple_field and I pass an object to a partial file. I do this in the partial :

<%= f.input :address,
            :as => :hidden,
            :label => "Address :",
            :input_html=>{
              :required => false,
              :class => "address"
            } %>

I want to use :as => hidden depending on a certain condition. I mean the field should be hidden if a condition is true. Is that possible to do?

Upvotes: 0

Views: 90

Answers (1)

Toby 1 Kenobi
Toby 1 Kenobi

Reputation: 5037

You could make your options hash separately and then add the hidden parameter if necessary

options = {
        :label => "Address :",
        :input_html=>{
          :required => false,
          :class => "address"
        } 
      }
if condition_is_true? then options[:as] = "hidden" end
<%= f.input :address, options %>

Upvotes: 1

Related Questions