ruby select使用心得

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)") %>

Ruby代码   收藏代码
  1. <%= text_field_tag  'product[no]',{}, :onchange => remote_function(:update => "no_result",    
  2.                            :method => "get",    
  3.                            :with => "'no=' + value",    
  4.                            :url => { :controller => :product:action => :is_show})     
  5.                            %>  
  6.                           <span id="no_result"></span>  

 

 

Ruby代码   收藏代码
  1. <%= select :obj:att,  @items, {}, :onchange => remote_function(:update => "sub_items",    
  2.        :method => "get",    
  3.        :with => "'item=' + value",    
  4.        :url => { :controller => :home:action => :get_sub_items})     
  5.        %>   

 

 

Ruby代码   收藏代码
  1. <%=select_tag ( 'product[style_id]',options_for_select([["未选择",0]]+Style.find(:all).map{|t| [t.name, t.id]}),   
  2.                                                                 :onchange => remote_function(:update => "sub_items",    
  3.                                                                :method => "get",    
  4.                                                                :with => "'style_id=' + value",    
  5.                                                                :url => { :controller => :product:action => :get_pic_look})   )%>  
 

 

Ruby代码   收藏代码
  1. <%=link_to_remote '删除',:update=>'mpart_table',  
  2.                                   :url=>{:controler=>:product,:action=>:del_row_mpart,:id=>mpart.id},  
  3.                                   :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...

具备以上技术,你就应该能写出来了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值