Skip to content

Instantly share code, notes, and snippets.

@nu7hatch
Created September 7, 2010 16:54
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 nu7hatch/568653 to your computer and use it in GitHub Desktop.
Save nu7hatch/568653 to your computer and use it in GitHub Desktop.
class Myapp
controller :libaries do
# ...
end
controller :book, :parent => :library do
before do
@lib = Library.find(params[:library_id] rescue nil
end
get :new do
@book = (@lib || current_account).books.build(params[:book] || {})
respond(@book)
end
post :create do
@analysis = (@lib || current_account).books.build(params[:book] || {})
@analysis.save
respond(@book, url(:books_index, :library_id => @lib ? @lib.id : nil))
end
end
end
# Now my app should responds for the following routings:
#
# /books, /books/new, etc... and /library/1/books, /library/1/books/new, etc.
#
# calling url(:books_index) i should get /books...
# ... but calling url(:books_index, :library_id => 1) i should get /library/1/books
#
# Of course there should be some additional option in controller for enabling such behaviour (like :shallow => true or smth), eg:
class Myapp
controller :books, :parent => :library, :shallow => true do
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment