I want to code simple app, with index and about page, without using db, all text will be in views. But I can’t call my controller methods, to change view.
Here is controller (home_controller.rb)
class HomeController < ApplicationController
def index
end
def about
end
end
layout:
!!!
%html
%head
%title Title
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= csrf_meta_tags
%body
.wrapper
= yield
.footer
home index view:
%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."
about view:
%h2 About
%h1
This is about page
%p
= link_to "Home", root_path
= link_to "About", :controller => "home", :action => "about"
%p
Lorem ipsum
in routes.rb I have root :to => 'home#index'
when i call my domain, i’ll get index, when i write: domain/home/index I get
No route matches [GET] “/home/index”
when I call about, it’s the same, how can I call my pages?
rake routes give me:
root / {:controller=>”home”, :action=>”index”}
You should define those routes as well. They won’t appear automatically.
For example, here’s what you can find in default generated routes.rb (at the end).
Uncomment this and you should be able to access
/home/indexand/home/about.