目前在添加控制器时,它有ex。 /仪表板/指标 我如何实现/ dashboard / editaccount ex?我怎样才能为这个(视图)“渲染”模板?
class DashboardController < ApplicationController
def index
u = Users.find(session[:id])
@username = u[:username]
end
def editaccount
##Some code??
end
end
我在轨道上的红宝石中完全是新的,所以希望你能回答我的初学问题。
答案 0 :(得分: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指南链接并搜索奇异资源)。