ruby select/select_tag

51 篇文章 0 订阅

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=>"删除部件分同时删除部件详情?"%> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Started GET "/notebooks/" for 127.0.0.1 at 2023-07-14 09:59:56 +0800 Processing by NotebooksController#index as HTML Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms) NoMethodError (undefined method `all' for Notebook:Module): app/controllers/notebooks_controller.rb:4:in `index' Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/actionpack-4.2.11.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (2.2ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/actionpack-4.2.11.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.1ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/actionpack-4.2.11.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.5ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/actionpack-4.2.11.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (9.8ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.2ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.2ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.2ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.1ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (8.4ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.1ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.2ms) Rendered /home/meiyi/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (15.1ms)
最新发布
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值