Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using a mutiple collection select form helper with habtm or has many associations in Rails

// where user has and belongs to many roles

# in your view
<%= collection_select :user, :role_ids, Role.find(:all, :order => 'name ASC'), :id, :name, { :selected => @user.role_ids }, { :multiple => true, :name => 'user[role_ids][]' } -%>

each_slice

require 'enumerator'

(1..10).each_slice(2) { |n| p n }
# [1, 2]
# [3, 4]
# [5, 6]
# [7, 8]
# [9, 10]
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS