我想编写简单的应用程序,索引和关于页面,而不使用数据库,所有的文本将在视图中。但我无法调用我的控制器方法来更改视图。 这里是控制器(home_controller.rb)简单的Ruby on Rails应用程序
class HomeController < ApplicationController
def index
end
def about
end
end
布局:
!!!
%html
%head
%title Title
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= csrf_meta_tags
%body
.wrapper
= yield
.footer
家索引视图:
%h2 Index
%h1
This is example page
%p
= link_to "Home", root_path
= link_to "About", :controller => "home", :action => "index"
%p
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
约视图:
%h2 About
%h1
This is about page
%p
= link_to "Home", root_path
= link_to "About", :controller => "home", :action => "about"
%p
Lorem ipsum
在routes.rb中我有root :to => 'home#index'
当我把我的域名,我会得到指数,当我写:域/首页/指数我得到
没有路由匹配[GET] “/首页/指数”
当我打电话时,它是一样的,我怎样才能打电话给我的网页? 耙路线给我:
根/ {:控制器=> “家”,:动作=> “索引”}
模板丢失 缺少模板首页/,应用/关于与{:处理器=> [:ERB,:建设者,:咖啡,:haml],:formats => [:html],:locale => [:en,:en]}。搜索:*“/ mnt/_Projects/exapmle2/app/views”wtf?我有这个 – byCoder 2012-02-10 11:56:25
你有'/ app/views/home/about.html.haml'吗? – 2012-02-10 11:57:30
ofc我有,嗯这很有趣 – byCoder 2012-02-10 12:00:04