最近经常使用select下拉标签
个人比较喜欢用select 和 select_tag 两个
[b]select_tag(name, option_tags = nil, options = {}) [/b]
Creates a dropdown selection box, or if the :multiple option is set to true, a multiple choice selection box.
Helpers::FormOptions can be used to create common select boxes such as countries, time zones, or associated records. option_tags is a string containing the option tags for the select box.
Options
:multiple - If set to true the selection will allow multiple choices.
:disabled - If set to true, the user will not be able to use this input.
Any other key creates standard HTML attributes for the tag.
select_tag "people", options_from_collection_for_select(@people, "name", "id")
# <select id="people" name="people"><option value="1">David</option></select>
---------------------------------
[b]select(object, method, choices, options = {}, html_options = {}) [/b]
Create a select tag and a series of contained option tags for the provided object and method. The option currently held by the object will be selected, provided that the object is available. See options_for_select for the required format of the choices parameter.
Example with @post.person_id => 1:
select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })
首先两者在传递参数上有点区别
select_tag传的就是一个参数(字符串)
select object/method 即对象和方法(属性)
options_from_collection_for_select(@people, "name", "id")
@people为对象货以对象为单元的数组,name为option的text值,id为option的value值
也可以用
options_for_select(Warehouse.find(:all).collect{|item|[item.name,item.id]}.insert(0,['请选择',0]))
分享到:
相关推荐
Select2用于Rails资产管道 是基于jQuery的选择框的替代品。 它支持搜索,远程数据集和结果的无限滚动。 select2-rails gem将Select2 jQuery插件与Rails资产管道集成在一起。 用法 安装select2-rails gem 将select2...
rails, Ruby on Rails 欢迎使用 RailsRails 是一个web应用程序框架,它包括根据 Model-View-Controller ( MVC ) Pattern 创建数据库备份的web应用程序所需的所有内容。理解 MVC Pattern 是理解 Rai
NULL 博文链接:https://hlee.iteye.com/blog/587000
ruby on rails轻松使用
使用Aptana+Rails开发Rails Web应用 有Aptana的安装配置等等,中文
使用RSpec 测试Rails 程序.pdf
shoppe-example, 在 Rails 中使用Shoppe平台的示例存储实现 这是一个 Rails 应用程序,它使用 Shoppe 构建。 它具有一个可以爱的设计,以充分演示Shoppe平台提供的功能以及它在 Rails 应用程序中的。 正在启动要开始...
jquery-rails, 一个 gem,用于自动使用jQuery和 Rails 3 railsjQuery 面向 Rails 如此伟大。这里 gem 提供:jQuery 1.7.2jQuery UI 1.8.18 ( 仅适用于 javascript )jQuery UJS适配器assert_select_j
Ruby on Rails轻松使用,掌握最新最热门的技术
rails-settings, 使用 Ruby on Rails 管理设置 Rails的设置 ruby gem,通过在单独的数据库表中将它们存储为序列化的哈希来处理。 包含命名空间和默认值。要求ruby 1.9.3或者更高版本Rails 3.1或者更高版本( 包括 ...
使用Rails构建可伸缩和可维护API的最佳方法
rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...
在过去的几年中,《Ruby on Rails Tutorial》这本书被视为介绍使用 Rails 进行 Web 开发的先驱者。 在这个全球互联的世界中,计算机编程和 Web 应用程序开发都在迅猛发展,我很期待能为中国的开发者提供 Ruby on ...
《Rails之道》按照Rails的各个子系统进行组织编排,分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器... 《Rails之道》是Rails的权威参考书,适合对Rails已经有一定了解的开发人员学习和使用。
博文链接:https://ziyoujiedao.iteye.com/blog/148307
[Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
jquery-datatables-rails, 用于 Rails的jquery数据表 gem jquery-datatables-rails 这个 gem 为 jQuery DataTables插件提供了方便,以便与 Rails 资产pipleine结合使用。 它提供所有基本的datatable文件,以及一些...
一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码
dckerize, 使用 Docker 容器的增压 Rails 开发 Dckerize 使用 Docker的增压 Rails 开发描述这个 gem 为你提供了一个很好的起始点,可以使用 Docker 对 Rails 5应用程序进行 containerize 。你会得到用于应用程序和...