Created
September 7, 2010 16:54
-
-
Save nu7hatch/568653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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