ruby on rails 3 - can't make a page root -
i noob in ruby on rails excuse question if stupid 1 :
i've added in routes.rb command :
root :to => "pages#home"
a have generated pages-controller using
rails generate controller pages
in pages_controller.rb i've defined function named home :
def home @text = "da" end
in views folder app in newly generated pages folder i've created file named home.html.erb . in i've placed following command :
<%= @text %>
the problem when start server app isn't rooted in home , when run localhost:3000/pages/home still doesn't work :
no route matches "/home"
you have created controller no view, try these commands
$ rails new myapp $ cd myapp $ rails g controller pages index <- create controller **plus** index view $ rm public/index.html
now edit routes.rb , add root :to => "pages#index
$ rails s
open http://localhost:3000 , you'll see new page.
i'm noob (i started coding in ruby 2 weeks ago)... strongly suggest book, such agile web development rails 4th ed. covered book in week , gave me lot of insight ruby , rails.
Comments
Post a Comment