select_tag:
<%= select_tag("article[type_id]", options_for_select([["请选择",nil]]+ArticleType.all.map{|t| [t.name, t.id]}, :selected=>record.type_id))%>
select 中的 :selected 值 要与 values里类型一致
<%= select_tag("article[type_id]", [["请选择",nil]]+ArticleType.all.map{|t| [t.name, t.id]}, :selected=>record.type_id)%>
或是写到help层 (更有效)
view
<%=ongoing_material_select 'material[][material_id]',f.material.id %>
help
def ongoing_provider_select name,selected,js_function=nil
select_tag name,
options_from_collection_for_select(Provider.ongoing_provider, "id", "name", selected),
{:include_blank=>'None', "onchange"=>"javascript:#{js_function}"}
end
select :
select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })
<select name="post[person_id]"> <option value=""></option> <option value="1" selected="selected">David</option> <option value="2">Sam</option> <option value="3">Tobias</option></select>
<%= select_tag('category[field_type]', options_for_select([['数值', 1], ['分类', 2],['文本',3]],@category_id_project.field_type), :onChange => "javascript:test('mune_x'+this.value)") %>
- <%= text_field_tag 'product[no]',{}, :onchange => remote_function(:update => "no_result",
- :method => "get",
- :with => "'no=' + value",
- :url => { :controller => :product, :action => :is_show})
- %>
- <span id="no_result"></span>
- <%= select :obj, :att, @items, {}, :onchange => remote_function(:update => "sub_items",
- :method => "get",
- :with => "'item=' + value",
- :url => { :controller => :home, :action => :get_sub_items})
- %>
- <%=select_tag ( 'product[style_id]',options_for_select([["未选择",0]]+Style.find(:all).map{|t| [t.name, t.id]}),
- :onchange => remote_function(:update => "sub_items",
- :method => "get",
- :with => "'style_id=' + value",
- :url => { :controller => :product, :action => :get_pic_look}) )%>
- <%=link_to_remote '删除',:update=>'mpart_table',
- :url=>{:controler=>:product,:action=>:del_row_mpart,:id=>mpart.id},
- :confirm=>"删除部件分同时删除部件详情?"%>
1.掌握显示、隐藏div的方法: obj_div.style.display = 'none' | 'block; 2.掌握给select添加事件的方法: obj_select.onclick = function(){}; 3.把option跟div们映射起来: option的value设置成1、2、3...,div的id设置成div1、div2、div3... 具备以上技术,你就应该能写出来了。