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>
prototype.js
<%= 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=>"删除部件分同时删除部件详情?"%>