Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created May 31, 2011 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gazer/1001350 to your computer and use it in GitHub Desktop.
Save Gazer/1001350 to your computer and use it in GitHub Desktop.
URL for models in JSON Response
class MyModel
attr_accessor :item_url
def as_json(options={})
{
:url => item_url
}.merge(self.attributes)
end
end
class SomeController
def some_action
@items = MyModel.search( .... )
render :json => @items.map {|x| x.item_url = url_for(x); x}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment