2013-04-30 26 views
1

我創建一個新的網頁是我的用戶可以有個人資料頁,我似乎無法找到使這樣的URL的方式:如何路由URL - 紅寶石

webpage.com/profile/username

要轉到我的profile_controller操作index並使用/ username中的變量。

但我似乎無法找到方法。

profile_controller.rb

class ProfileController < ApplicationController 
    def index 
    profile_info = Profile.find(params[:username]) 
    end 
end 

我也試圖與routes.rb中去解決它周圍,但不能使它...

+0

帖子'耙routes'的輸出。這將給我們所有的配置路線和幫手功能。 – marcantonio 2013-04-30 20:55:20

回答

2

在你的routes.rb這條路線應地圖坐上/型材/用戶名請求您的配置文件控制的指標和行動params中傳遞用戶名值:用戶名]

get '/profiles/:username' => 'profiles#index' 
+0

Okei,這個伎倆! 非常感謝! – 2013-04-30 20:59:51