No commit activity in last 3 years
No release in over 3 years
Exposes ActiveRecord::Base.for_select for use with Rails' ActionView::Helpers::FormTagHelper#select_tag
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3

Runtime

>= 1.6
>= 4.2
 Project Readme

Rails for_select

Build Status

Simplifies delivering content to a rails form select_tag by exposing the for_select class-method on any class inheriting from ActiveRecord::Base.

User.for_select 
# => [["name", 1], ["other name", 2], ...]

For those models that doesn't defaultly have a name, or that should use another id field, you can customize it like this.

User.for_select(id: :uuid) 
# => [["name", 'uuid1'], ["other name", 'uuid2'], ...]

User.for_select(name: :full_name) 
# => [["full name", 1], ["other full name", 2], ...]

If you're records doesn't have timestamps you can use another cache key.

User.for_select(cache_key: :created_on) 
# => [["name", 1], ["other name", 2], ...]

Putting it all together with a rails form

= form_for Post do |f|
  = f.select :author, User.for_select