Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created March 7, 2012 08:53
Show Gist options
  • Save jlebrech/1992026 to your computer and use it in GitHub Desktop.
Save jlebrech/1992026 to your computer and use it in GitHub Desktop.
DSL Generators
Scaffold do
route "/" do |r|
controller :welcome do |c|
get :index do
html do
table :posts_model, :except => :secret_field
list :users_model
end
end
end
end
route "/posts" do
controller :post do |c|
get :index do
html do
list :posts_model do
list :comments_model, :username
end
end
end
post :create do
html do
flash
save
list :posts_model
end
end
get :rdf do
xml :posts_model do
exclude => {:secret_field1, :secret_field2},
embeded :customfield1 do
json :comments_model do |j|
:name j.fullname.shorten
:comment j.comment.ellipsis
:created_at j.created_at.strftime("dd/mm/yy")
end
end
end
end
end # end of post controller
end # end of posts route
route "/comments"
controller :comment, :comment_model do # name of route, name_of_assumed_model
get :new do
html do
list :tags_model, :include => {:id, :name, :size}
form # this would create a form for the assumed_model
end
end
post :create do
save
end
patch :update do
save
redirect :index
end
get :edit do
html do
form
end
end
delete :destroy
put :flag_comment do
json :comments_model, :id, :reason
end
end # end of comments controller
end # end of comments route
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment