Closed masarakki closed 12 years ago
+1 for this.
In my case I don't want to log an page URL but route spec and parameters instead.
@masarakki this no longer merges cleanly.
How does using a mounted engine in Rails affect this? Should it be reset inside the if 'pass' == headers['X-Cascade']
block?
@pixeltrix
i want to use config/routes.rb, but all information of config/routes are dropped after built router.
i want to use config/routes.rb to find resources automatically, like
resources :users do
resources :blogs do
resources :articles
...
when /users/1/blogs/20/articles, i want to find automatically as User.find(1).blogs.find(20).articles, so first, i want to know what route was chosen. then, i will change :resources method to store their structure of resources in route.
@masarakki this is a common pattern, e.g:
class ArticlesController < ApplicationController
before_filter :load_user
before_filter :load_blog
def index
@articles = @blog.articles.all
end
protected
def load_user
@user = User.find(params[:user_id])
end
def load_blog
@blog = @user.blogs.find(params[:blog_id])
end
end
What do you need that isn't met by this standard functionality?
i want to do that automatically, and support multi-routings with one controller and one view.
i wrote what i want to do, see it: https://github.com/masarakki/parent_resource/tree/ver2
now, i'm trying to parse url and match with models, instead of using route information, if you say it is better than changing journey, i will give up.
You can attach values to a route using defaults that don't have to be part of the url, e.g:
resources :posts do
resources :comments, :defaults => { :parent_resource => :posts }
end
resources :comments
Then when nested route is access :parent_resource
will be present in the params hash. You could even override resource
and resources
in a module and include that into Mapper
so that the extra information is added automatically.
Your pull request wouldn't help with what you're trying to achieve as the route has no information regarding the resources, e.g:
resources :posts, :only => :index
and
get '/posts', :to => 'posts#index', :as => :posts
result in the same routes in Journey.
@pixeltrix It is what i realy wanted !!! i change to use it, thanks!
I want to know what route was detected in controller, so added route info to env and call controller with it.