Skip to content

Commit

Permalink
Add :title option to fields_for
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiofullscreen committed Aug 22, 2014
1 parent 3377078 commit 0b5614e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/bh/helpers/form/fields_for_helper.rb
Expand Up @@ -9,9 +9,8 @@ module FieldsForHelper
def fields_for(record_object = nil, fields_options = {}, &block)
fields_options[:layout] ||= @options[:layout]
fields_options[:errors] ||= @options[:errors]
fieldset record_object.to_s.humanize do
super record_object, fields_options, &block
end
title = fields_options.delete(:title) { record_object.to_s.humanize }
fieldset(title) { super record_object, fields_options, &block }
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/helpers/form/fields_for_helper_spec.rb
Expand Up @@ -15,7 +15,12 @@
expect(form).to include 'fieldset class="panel panel-default">'
end

specify 'generates a title in the panel heading from the field name' do
context 'given a title option, uses the provided title' do
let(:options) { {title: 'Your address'} }
it { expect(form).to include '<div class="panel-heading">Your address</div>' }
end

specify 'not given a title, generates one from the field name' do
expect(form).to include '<div class="panel-heading">Address</div>'
end

Expand Down

0 comments on commit 0b5614e

Please sign in to comment.