I am using Rails 3. And I'm wondering how to pass params to some blocks in routes.rb
.
What I'm trying to do is to make a catch all
route, that check from slugs
database the model name of it by the id.
After getting the model name
i pluralize it to get the controller name.
match '/:id', :controller => proc { Slug.find_by_iid(params[:id]).model.pluralize }, :action => :show
The table slugs
model iid
----- -----
post 4d2c7de0c5abe7f8a9000007
item 4d2c7de0c5abe7f809000004
When I try to access some pages like /4d2c7de0c5abe7f8a9000007
I got this error:
Started GET "/4d2c7de0c5abe7f8a9000007" for
127.0.0.1 at 2011-01-12 00:04:31 +0200
ActionController::RoutingError (wrong constant name #<Proc:0x0000010337c310@):
Rendered /Users/amr/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
The expected is to point to posts#view with iid: 4d2c7de0c5abe7f8a9000007