我正在使用select_tag并使用它从数据库中填充它。
<%= 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;" } %>
但是在包含“:include_blank”时,我收到以下错误:
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 ...
^
如何在上面的代码中包含空白或提示值。
日Thnx。
答案 0 :(得分:3)
将:include_blank
电话包含在此内:{}
<%= select_tag 'project', options_from_collection_for_select([],"id", "name"), {:include_blank => 'Select', :onblur => "myblur(this);", :onChange=> "submit_selected(this);", :style=> "visibility:visible;" } %>
答案 1 :(得分:1)
阅读帖子Can I include blank field in select_tag?,以便更好地了解如何使用select_tag
。
如果您的Rails版本不是3.0或更高版本,请参阅:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1987-select_tag-should-allow-include_blank-option了解如何覆盖select_tag
form_tag_helper.rb
方法
这会将功能添加到:include_blank => true/false
或:include_blank => '<String>'