Commit d89eda9273d95caa17aba76db36a9f447dc778c3

Authored by Dan Croak
1 parent 9f845b63

updated blitz, semi formal

vendor/plugins/blitz/features/step_definitions/view_steps.rb
... ... @@ -32,7 +32,7 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do
32 32 " <fieldset class=\"inputs\">\n" <<
33 33 " <%= form.string :title %>\n" <<
34 34 " <%= form.text :body %>\n" <<
35   - " <%= form.collection :user %>\n" <<
  35 + " <%= form.belongs_to :user %>\n" <<
36 36 " </fieldset>\n" <<
37 37 " <fieldset class=\"buttons\">\n" <<
38 38 " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
... ...
vendor/plugins/blitz/generators/support/generator_helper.rb
... ... @@ -36,7 +36,7 @@ module Blitz
36 36  
37 37 def name_and_type(column)
38 38 if belongs_to_column?(column.name)
39   - [column.name.gsub("_id", ""), :collection]
  39 + [column.name.gsub("_id", ""), :belongs_to]
40 40 else
41 41 [column.name, column.type]
42 42 end
... ...
vendor/plugins/semi_formal/lib/semi_formal.rb
... ... @@ -42,25 +42,27 @@ class SemiFormal &lt; ActionView::Helpers::FormBuilder
42 42 "<div>"
43 43 end
44 44  
45   - def collection(field, *args)
  45 + def belongs_to(field, *args)
46 46 options = args.extract_options!
47 47  
48 48 reflection = @object.class.reflect_on_association(field)
49   - collection = reflection.class.all.collect {|each| [each.name, each.id] }
  49 + collection = reflection.klass.all.collect {|each| [each.to_s, each.id] }
50 50  
51   - html_options = {}
52   - options[:include_blank] = true
  51 + options[:select] ||= {}
  52 + options[:select][:include_blank] = true
53 53  
54   - if [:has_many, :has_and_belongs_to_many].include?(reflection.macro)
55   - html_options[:multiple] ||= true
56   - html_options[:size] ||= 5
57   - end
58   -
59   - "<div class=\"collection\">" +
  54 + "<div class=\"belongs_to\">" +
60 55 label(field, options[:label] || {}) +
61   - select(field, collection, options, html_options)
  56 + select(field, collection, options[:select] || {})
62 57 "<div>"
63 58 end
  59 +
  60 + # has_many?
  61 + # if [:has_many, :has_and_belongs_to_many].include?(reflection.macro)
  62 + # html_options[:multiple] ||= true
  63 + # html_options[:size] ||= 5
  64 + # end
  65 +
64 66 end
65 67  
66 68 ActionView::Base.default_form_builder = SemiFormal
... ...