【发布时间】:2014-01-10 13:18:29
【问题描述】:
我目前没有索引视图 (app/views/mycontroller/index.html.erb),但如果用户只输入以下内容,我想指定一个默认视图:localhost:3000/mycontroller
对 RoR 非常陌生。我现在的config/routes.rb:
MyTestApp::Application.routes.draw do
get "team/thatguy"
get "home/about"
root :to => "home#about"
end
在我的控制器中,我一直在玩重定向,但所需的解决方案是只显示较小的 uri localhost:3000/mycontroller。
app/controllers/home_controller.rb:
class HomeController < ApplicationController
def index
render "home/about"
end
def about
@title = "My Title"
end
end
【问题讨论】:
-
当用户访问
/mycontroller时,你想渲染哪个模板? -
我只有一个模板。这是一个非常基本的、完全静态的网站,只有一个联系表格。
标签: model-view-controller ruby-on-rails-4 routes