include_blank in form select_option not working

2.2k views Asked by At

I am trying to include a default blank first option in a select field as follow:

= f.select :role, options_for_select(User::ROLE), {}, include_blank: true, class: "form-control"

which is not giving the expected outcome.

User::ROLE is an array in the User class as follow:

ROLE = ["user", "doctor", "manager"]

How can I make the select option in the field to return a blank option for first select, without having to include a blank option as first element of my ROLE array? Thanks

2

There are 2 answers

1
Arup Rakshit On BEST ANSWER

Below should fix it:

= f.select :role, options_for_select(User::ROLE), { include_blank: true} , { class: "form-control" }

Here is the method signature:

select(object, method, choices = nil, options = {}, html_options = {}, &block) public

0
Pavan On

From the API,it should be

= f.select :role, options_for_select(User::ROLE),{include_blank: true}, {class: "form-control" }