aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/prototype_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/helpers/prototype_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index ed3f7b7d7f..9fa27d6386 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -384,8 +384,19 @@ module ActionView
# page['blank_slate'] # => $('blank_slate');
# page['blank_slate'].show # => $('blank_slate').show();
# page['blank_slate'].show('first').up # => $('blank_slate').show('first').up();
+ #
+ # You can also pass in a record, which will use ActionController::RecordIdentifier.dom_id to lookup
+ # the correct id:
+ #
+ # page[@post] # => $('post_45')
+ # page[Post.new] # => $('new_post')
def [](id)
- JavaScriptElementProxy.new(self, id)
+ case id
+ when String, Symbol, NilClass
+ JavaScriptElementProxy.new(self, id)
+ else
+ JavaScriptElementProxy.new(self, ActionController::RecordIdentifier.dom_id(id))
+ end
end
# Returns an object whose <tt>#to_json</tt> evaluates to +code+. Use this to pass a literal JavaScript