I have problems getting clear about the new routing system of Rails 3+.
I want to match "/:name" to :controller => 开发者_高级运维:profiles, :action => :show, :name => name
How do I realize this?
I tried with match "/:name" => "profiles#show"
but this just uses the :name as :id...
Yours Joern.
With match "/:name" => "profiles#show"
this is going to trigger the show
action on the profiles
controller. Inside that controller instance you can access the matched URL from params[:name]
I assume you are trying to get a Model record by name instead of id, thus you must modify your show
action. For instance,
def show
@profile = Profile.find_by_name(params[:name])
end
精彩评论