throughcheckboxes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,3 @@
1
+ Very beta rails gem. No docs, no tests.
2
+
3
+ I'll try to provide them soon.
@@ -0,0 +1,29 @@
1
+ module ThroughCheckboxes
2
+
3
+ module Checkboxesfor
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def checkboxes_for(*args)
9
+ for relation in args
10
+ instance_eval do
11
+ define_method "#{relation}_ids=" do |ids|
12
+ self.send("#{relation}=",ids.select {|id| id.present?}.map {|id| relation.to_s.classify.constantize.find(id)})
13
+ end
14
+
15
+ define_method "#{relation}_ids" do
16
+ self.send("#{relation}").map {|e| e.id}
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,22 @@
1
+ module ThroughCheckboxes
2
+
3
+ module CheckboxesforHelpers
4
+
5
+ module FormBuilderExtension
6
+
7
+ def checkboxes_for(relation)
8
+ output = ""
9
+ output << "#{self.label(relation)}<br />"
10
+ for record in relation.to_s.classify.constantize.all
11
+ output << @template.check_box_tag("#{@object_name}[#{relation}_ids][]",record.id,self.object.send(relation).include?(record))
12
+ output << "#{record}<br />"
13
+ end
14
+ output << @template.hidden_field_tag("#{@object_name}[#{relation}_ids][]")
15
+ output.html_safe
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Throughcheckboxes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,2 +1,10 @@
1
- module Throughcheckboxes
1
+ require 'throughcheckboxes/checkboxes_for'
2
+ require 'throughcheckboxes/checkboxes_for_helpers'
3
+
4
+ if defined?(ActiveRecord::Base)
5
+ ActiveRecord::Base.send :include, ThroughCheckboxes::Checkboxesfor
6
+ end
7
+
8
+ if defined?(ActionView::Helpers::FormBuilder)
9
+ ActionView::Helpers::FormBuilder.send :include,ThroughCheckboxes::CheckboxesforHelpers::FormBuilderExtension
2
10
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["lucapette@gmail.com"]
11
11
  s.homepage = "http://rubygems.org/gems/throughcheckboxes"
12
12
  s.summary = %q{This gem will handle has_many :through association with checkboxes}
13
- s.description = %q{This gem will handle has_many :through association with checkboxes. Very beta( very=='no tests')}
13
+ s.description = %q{This gem will handle has_many :through association with checkboxes. Very beta, no tests, no docs yet)}
14
14
 
15
15
  s.rubyforge_project = "throughcheckboxes"
16
16
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - lucapette
@@ -18,7 +18,7 @@ date: 2011-03-11 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: This gem will handle has_many :through association with checkboxes. Very beta( very=='no tests')
21
+ description: This gem will handle has_many :through association with checkboxes. Very beta, no tests, no docs yet)
22
22
  email:
23
23
  - lucapette@gmail.com
24
24
  executables: []
@@ -30,8 +30,11 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - .gitignore
32
32
  - Gemfile
33
+ - README.textile
33
34
  - Rakefile
34
35
  - lib/throughcheckboxes.rb
36
+ - lib/throughcheckboxes/checkboxes_for.rb
37
+ - lib/throughcheckboxes/checkboxes_for_helpers.rb
35
38
  - lib/throughcheckboxes/version.rb
36
39
  - throughcheckboxes.gemspec
37
40
  has_rdoc: true