2012-09-05 43 views
-1

我有一个基本的Ruby on Rails服务器设置。如何让index.html.rb运行

在routes.rb中我有这样的:

ActionController::Routing::Routes.draw do |map| 

    map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 

    root :to => "home#index" 
end 

在我的控制器/ application_controller.rb我有这样的:

class ApplicationController < ActionController::Base 
    helper :all # include all helpers, all the time 
    protect_from_forgery # See ActionController::RequestForgeryProtection for details 
end 

最后我有/app/views/posts/index.html .erb中包含一些基本的HTML。如何让我的页面指向该HTML文件。

+0

您可以生成帖子控制器并添加索引操作:'rails generate controller posts index'。在默认情况下,对帖子控制器的索引操作将使用'app/views/posts/index.html.erb'模板。 – taro

+0

不知道你的意思是'localhost:3000/posts'还是'<%= link_to“Posts”,posts_path'%> – MurifoX

+0

假设我删除posts文件夹,该如何让网站转到HTML.rb页面? – sebi

回答

0

试试这个:

ActionController::Routing::Routes.draw do 
    root :to => "main_controller#index" 
    match 'home' => 'main_controller#index' 
end 

其中main_controller这是要作为主页使用控制器的名称。

match将允许您输入localhost:3000/home,它将与您指定的控制器进行匹配。

您可以通过运行命令rake routes来检查您的有效路线,它会为您提供项目中的路线列表。

检查http://guides.rubyonrails.org/routing.html -5检查和测试路线。