Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### enhancements

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

## 2.2.0 (February 13, 2018)

Expand Down
2 changes: 1 addition & 1 deletion lib/enumerize/hooks/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Hooks
module FormtasticFormBuilderExtension

def input(method, options={})
klass = object.to_model.class
klass = object && object.to_model.class

if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[method])
options[:collection] ||= attr.options
Expand Down
2 changes: 1 addition & 1 deletion lib/enumerize/hooks/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def input_field(attribute_name, options={})
private

def add_input_options_for_enumerized_attribute(attribute_name, options)
klass = object.to_model.class
klass = object && object.to_model.class

if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[attribute_name])
options[:collection] ||= attr.options
Expand Down
8 changes: 8 additions & 0 deletions test/formtastic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,12 @@ def persisted?

assert_select 'input[type=text]'
end

it 'does not affect forms without object' do
concat(semantic_form_for('') do |f|
f.input(:name)
end)

assert_select 'input[type=text]'
end
end
8 changes: 8 additions & 0 deletions test/simple_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ def persisted?

assert_select 'input.string'
end

it 'does not affect forms without object' do
concat(simple_form_for('') do |f|
f.input(:name)
end)

assert_select 'input.string'
end
end