Hitesh
Hitesh

Reputation: 81

Rails SelectTag include_blank not working

i am using select_tag and populating it from the database using this.

<%= select_tag 'project', options_from_collection_for_select(@issue_statuses,"id", "name"), :include_blank  => 'Select' , html_options = { :onblur => "myblur(this);", :onChange=> "submit_selected(this);", :style=> "visibility:visible;" } %>

but on including ":include_blank" i am getting following error:

compile error
/home/hitesh/redmine-1.3.0-1/apps/redmine/vendor/plugins/redmine_polls/app/views/questions/index.html.erb:42: syntax error, unexpected ')', expecting tASSOC
...le=> "visibility:visible;" } ).to_s); @output_buffer.concat ...
                          ^

how to include blank or prompt value in the above code.

thnx.

Upvotes: 2

Views: 2458

Answers (2)

MPK
MPK

Reputation: 133

Read the post Can I include blank field in select_tag? to get a better understanding of how to use select_tag.

If your Rails version is NOT 3.0 or greater then refer to this: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1987-select_tag-should-allow-include_blank-option to see how to override the default select_tag method in form_tag_helper.rb

This will add the functionality to :include_blank => true/false or :include_blank => '<String>'

Good luck.

Upvotes: 2

Arun Kumar Arjunan
Arun Kumar Arjunan

Reputation: 6857

Enclose the :include_blank call within this: {}

<%= select_tag 'project', options_from_collection_for_select([],"id", "name"), {:include_blank  => 'Select', :onblur => "myblur(this);", :onChange=> "submit_selected(this);", :style=> "visibility:visible;" } %>

Upvotes: 4

Related Questions