Skip to content

Commit

Permalink
Use InstanceTag / TextArea based on Rails version
Browse files Browse the repository at this point in the history
Use InstanceTag for Rails 3 and TextArea otherwise. This allows
sir-trevor-rails to work on Rails 4.

This is based on the fix for the same issue contained within
#16
  • Loading branch information
icedtoast authored and Dan Brown committed Jan 9, 2015
1 parent 973da9f commit 4b34035
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/sir-trevor/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ def sir_trevor_text_area(object_name, method, options = {})
input_html[:class] = "sir-trevor-area visuallyhidden"
hash = input_html.stringify_keys

instance_tag = ActionView::Base::InstanceTag.new(object_name, method, self, options.delete(:object))
instance_tag.send(:add_default_name_and_id, hash)

output_buffer = ActiveSupport::SafeBuffer.new
output_buffer << instance_tag.to_text_area_tag(input_html)
# support both Rails 3 & 4
if defined? ActionView::Base::InstanceTag
instance_tag = ActionView::Base::InstanceTag.new(object_name, method, self, options.delete(:object))
instance_tag.send(:add_default_name_and_id, hash)
output_buffer << instance_tag.to_text_area_tag(input_html)
else
instance_tag = ActionView::Helpers::Tags::TextArea.new(object_name, method, self, input_html)
instance_tag.send(:add_default_name_and_id, hash)
output_buffer << instance_tag.render
end

output_buffer

Expand Down

0 comments on commit 4b34035

Please sign in to comment.