为一页着陆页生成路线?

Phi*_*hil 2 routes ruby-on-rails

我正在尝试使用 Rails 和威廉·盖尔菲(William Ghelfi)撰写的精美着陆页指南(谢谢!) http://www.williamghelfi.com/blog/2013/08/04/bootstrap-in-practice-a -登陆页面/

我已经使用 Rails 4.0.0 在 Rails 上启动了一个新项目

从 RoR 登录页面可以看出,服务器在 localhost:3000 上运行良好。

我的问题是使用 RoR 为单页登录页面生成路由和控制器的最佳方法是什么?

现在,当我尝试指向 localhost:3000/lpd.html 时,我收到错误 No route matching [GET] "/lpd.html" No routes defined。

nat*_*vda 5

如果你只想要一个静态页面,你可以将 移动lpd.htmlpublic文件夹,它就会工作。但是许多 Rails 网站都有半静态页面。

所以你可以创建一个LandingControllerHomeController你保存所有半静态页面的地方。例如家,关于,联系我们...

因此,例如,执行以下操作

rails g controller Home index about
Run Code Online (Sandbox Code Playgroud)

这将生成HomeController具有两个操作indexabout,具有相应视图和默认路由的。因此app/views/home将添加两个视图,然后您可以根据需要进行编辑。

然后您可以config/routes.rb按如下方式编辑路由(in ):

get '/about' => 'home#about'
root_to 'home#index'
Run Code Online (Sandbox Code Playgroud)

这将确保这http://localhost:3000将是您的home/index视图,并且http://localhost:3000/about将是您的关于页面。