Moved from making a default form builder to aliasing the form_tag function in the form helper.

This commit is contained in:
Devon Noonan 2012-10-01 14:59:59 -04:00
parent f39a2f1422
commit 6975b5abd7
3 changed files with 23 additions and 12 deletions

View File

@ -1,11 +1,12 @@
require "sisyphus-rails/version" require "sisyphus-rails/version"
require "sisyphus-rails/engine" require "sisyphus-rails/engine"
require "sisyphus-rails/form_helper" # require "sisyphus-rails/form_helper"
require "sisyphus-rails/form_tag_helper"
module Sisyphus module Sisyphus
end end
if defined?(ActionView::Base) # if defined?(ActionView::Base)
ActionView::Base.default_form_builder = Sisyphus::FormBuilder # ActionView::Base.default_form_builder = Sisyphus::FormBuilder
end # end

View File

@ -1,8 +0,0 @@
module Sisyphus
class FormBuilder < ActionView::Helpers::FormBuilder
def initialize(object_name, object, template, options, block=nil)
super
@template.output_buffer << "<script type=\"text/javascript\">$(document).ready(function() {$('##{self.options[:html][:id]}').sisyphus();});</script>".html_safe
end
end
end

View File

@ -0,0 +1,18 @@
module ActionView
module Helpers
module FormTagHelper
def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block)
buf = ActiveSupport::SafeBuffer.new
if options.has_key?(:id)
buf.safe_concat("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus();});</script>")
end
buf << form_tag_without_sisyphus(url_for_options, options, &block)
end
alias_method_chain :form_tag, :sisyphus
end
end
end