Method: ActiveResource::Base.element_path
- Defined in:
- lib/active_resource/base.rb
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
Gets the element path for the given ID in id. If the query_options parameter is omitted, Rails will split from the prefix options.
Options
prefix_options - A hash to add a prefix to the request for nested URLs (e.g., :account_id => 19 would yield a URL like /accounts/19/purchases.json).
query_options - A hash to add items to the query string for the request.
Examples
Post.element_path(1)
# => /posts/1.json
class Comment < ActiveResource::Base
self.site = "https://37s.sunrise.com/posts/:post_id"
end
Comment.element_path(1, :post_id => 5)
# => /posts/5/comments/1.json
Comment.element_path(1, :post_id => 5, :active => 1)
# => /posts/5/comments/1.json?active=1
Comment.element_path(1, {:post_id => 5}, {:active => 1})
# => /posts/5/comments/1.json?active=1
762 763 764 765 766 767 |
# File 'lib/active_resource/base.rb', line 762 def element_path(id, = {}, = nil) () , = () if .nil? "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}#{format_extension}#{query_string(query_options)}" end |