开发者_高级运维:profiles, :action => :show, :name => name" />
开发者

Rails 3 Routes - routing a parameter different to :id

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜