Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Created August 23, 2009 14:19
Show Gist options
  • Save ehlyzov/173298 to your computer and use it in GitHub Desktop.
Save ehlyzov/173298 to your computer and use it in GitHub Desktop.
# Controller
def dull_party
Human.class_eval do
def login
name
end
def hello_world
'Hello world!'
end
def extended_name
name + '!!!'
end
end
Toy.class_eval do
def railsize2
railsize("We ","are happy ","to code ","with power of X ","and Y")
end
end
Pet.class_eval do
def pet_type_name
pet_type.class_name
end
end
@humans = Human.all[0..1]
@humans_json = @humans.to_json(
:methods => [
:login,
:enhanced_name,
:hello_world],
:include => {
:pets => {
:except => [
:human_id,
:pet_type_id],
:methods => :pet_type_name,
:include => {
:toys => {
:methods => [:railsize2]
}
}
}}
)
respond_to do |format|
format.json { render :json => humans_json }
format.html { render :inline => "<%= debug(@humans_json) %>" }
end
end
# Controller
def jazz_party
@humans = Human.all[0..1]
respond_to do |format|
format.json { }
end
end
#View (jazz_party.json.jazz)
-@humans => people
:only
.name => login
:code => enhanced_name
name + "!!!"
:code => hello_world
"Hello world!"
+pets => animals
:except
.human_id
.pet_type_id
+toys
:methods
.railsize("We ","are happy ","to code ","with power of X ","and Y")
<pet_type
:only
.class_name => pet_type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment