2013-03-25 99 views
0

當前當添加一個控制器它有前。 /儀表板/索引 我如何實現/儀表板/ editaccount前?我如何「渲染」這個模板(視圖)?更多的功能在一個控制器/東西/東西

class DashboardController < ApplicationController 
    def index 
    u = Users.find(session[:id]) 
    @username = u[:username] 
    end 

    def editaccount 
    ##Some code?? 
    end 
end 

我完全在軌道上的紅寶石新,所以希望你能回答我的初學者問題。

回答

1
class DashboardsController < ApplicationController 
    def index 
    user = Users.find(session[:id]) 
    @username = user[:username] 
    end 

    def edit_account 
    # Your code 
    # automatically renders the 'edit_account' template 
    end 
end 

# config/routes.rb 
resource :dashboard do 
    get 'edit_account', on: :collection 
end 

Routing in the Rails Guides上了解更多信息。

請注意,我將您的DashboardController的命名更改爲DashboardsController。通常在Rails中以複數名稱命名控制器,即使在使用單數路徑時(請參閱上面的Rails指南鏈接,並搜索單數資源的)。