Skip to content

Commit 19ca550

Browse files
authored
Merge pull request #308 from brainspec/fix/issue-307
Support SimpleForm/Formtastic forms without object.
2 parents 56c9da0 + fb80a28 commit 19ca550

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### enhancements
44

55
### bug fix
6+
Fix issue with SimpleForm/Formtastic forms without object. (by [@nashby](https://github.com/nashby))
67

78
## 2.2.0 (February 13, 2018)
89

lib/enumerize/hooks/formtastic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Hooks
55
module FormtasticFormBuilderExtension
66

77
def input(method, options={})
8-
klass = object.to_model.class
8+
klass = object && object.to_model.class
99

1010
if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[method])
1111
options[:collection] ||= attr.options

lib/enumerize/hooks/simple_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def input_field(attribute_name, options={})
1717
private
1818

1919
def add_input_options_for_enumerized_attribute(attribute_name, options)
20-
klass = object.to_model.class
20+
klass = object && object.to_model.class
2121

2222
if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[attribute_name])
2323
options[:collection] ||= attr.options

test/formtastic_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,12 @@ def persisted?
124124

125125
assert_select 'input[type=text]'
126126
end
127+
128+
it 'does not affect forms without object' do
129+
concat(semantic_form_for('') do |f|
130+
f.input(:name)
131+
end)
132+
133+
assert_select 'input[type=text]'
134+
end
127135
end

test/simple_form_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,12 @@ def persisted?
128128

129129
assert_select 'input.string'
130130
end
131+
132+
it 'does not affect forms without object' do
133+
concat(simple_form_for('') do |f|
134+
f.input(:name)
135+
end)
136+
137+
assert_select 'input.string'
138+
end
131139
end

0 commit comments

Comments
 (0)