ruby select/select_tag
3031 ワード
select_tag:
<%= select_tag("article[type_id]),options_for_select([[選択してください]]]++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 :
prototype.js
<%= select_tag("article[type_id]),options_for_select([[選択してください]]]++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=>" ?"%>