提交 3cfb894b 编写于 作者: T Thomas Fuchs

Allow JSON-style values for the :with option of observe_field. Closes #8557 [kommen]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6930 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 13058b01
*SVN*
* Allow JSON-style values for the :with option of observe_field. Closes #8557 [kommen]
* Remove RAILS_ROOT from backtrace paths. #8540 [Tim Pope]
* Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces. [Jeremy Kemper]
......
......@@ -698,7 +698,7 @@ def method_option_to_s(method)
end
def build_observer(klass, name, options = {})
if options[:with] && (options[:with] !~ /[=(.]/)
if options[:with] && (options[:with] !~ /[\{=(.]/)
options[:with] = "'#{options[:with]}=' + value"
else
options[:with] ||= 'value' unless options[:function]
......
......@@ -174,6 +174,17 @@ def test_observe_field
observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
end
def test_observe_field_using_with_option
expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + value})})\n//]]>\n</script>)
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id')
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + value")
end
def test_observe_field_using_json_in_with_option
expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:{'id':value}})})\n//]]>\n</script>)
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}")
end
def test_observe_field_using_function_for_callback
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>),
observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册