Skip to content

Commit

Permalink
Fix a crash when using form for Ransack
Browse files Browse the repository at this point in the history
Fix an issue that causes bootstrap form builder to crash when a field is assigned to a Ransack Search Class, by no longer assuming the object always responds to `on_validators` while figuring out whether the field is required.
  • Loading branch information
kieranklaassen committed Jun 5, 2015
1 parent f190562 commit 56dfe37
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ def required_attribute?(obj, attribute)
return false unless obj and attribute

target = (obj.class == Class) ? obj : obj.class
target_validators = target.validators_on(attribute).map(&:class)

target_validators = if target.respond_to? :validators_on
target.validators_on(attribute).map(&:class)
else
[]
end

has_presence_validator = target_validators.include?(
ActiveModel::Validations::PresenceValidator)
Expand Down

0 comments on commit 56dfe37

Please sign in to comment.