Rails routing, how would I create this slug-style route?
I'm trying to create a url that looks like this:
www.example.com/something/:a_slug
So a url that is /some开发者_JS百科thing where something is not a controller (but it is mapped to a controller, like a controller alias). Something is a fixed word.
Then :a_slug can be any slug passed into the a controller and picked up on an action.
Sort of a very custom show resource url.
It seems simple but I can't seem to get the route right.
Cheers!
routes.rb
match 'something/:a_slug' => 'widgets#show'
app/controllers/widgets_controller.rb
class WidgetsController < ApplicationController
def show
render :text => params[:a_slug]
end
end
And as if by magic, GET /something/feh
shows feh
in the browser.
Oh, of course this is for rails 3. It's similar for rails 2 but you didn't specify a requirement there.
精彩评论