Hi all,
I’m coming from the PHP world and I’m trying to learn Ruby and Rails.
I’m having a problem where I keep getting the error “No route matches /
home/view” even though I have it defined it. I’d appreciate any help
on this. I’m using rails 3.0 and the setting for the environment is
“development”.
routes.rb
Site::Application.routes.draw do
get “home/index”
root :to => “home#index”
end
home_controller.rb
class HomeController < ApplicationController
def index
@page_title = “Home”
end
def view
@page_title = “View page”
end
end
and I have two view files in app/views/home:
index.html.erb
view.html.erb
I just defined a route:
get “home/view”
And it works… But I’m wondering if I HAVE to define a route for
every page on my site. I was assuming if the controller/action existed
it would just show it?
can you reach to index action, or it is inaccessible too?
I can see the index action if I go to /
If I go to home/index, I cannot see the page unless I add get “home/
index” to my routes
My routes file looks like this:
routes.rb
Site::Application.routes.draw do
root :to => “home#index”
end
home_controller.rb
class HomeController < ApplicationController
def index
@page_title = “Home”
end
def view
@page_title = “View page”
end
end
and I have two view files in app/views/home:
index.html.erb
view.html.erb
On 21 August 2010 20:35, DanielMedia [email protected] wrote:
I just defined a route:
get “home/view”
And it works… But I’m wondering if I HAVE to define a route for
every page on my site. I was assuming if the controller/action existed
it would just show it?
Have a look at the rails guide on routing ( at
http://guides.rubyonrails.org/ ). All should then become clear (or at
least less muddy). Check out the other guides also if you have not
already done so.
Colin