can't make a page root
I am a noob in ruby on rails so excuse this question if it is a stupid one :
I've added in my routes.rb the command :
root :to => "pages#home"
a have generated a pages-controller using
rails generate controller pages
in my pages_controller.rb i've defined a function named home :
def home
@text = "da"
end
in the views folder from my app in the newly generated pages folder i've created a file named hom开发者_StackOverflowe.html.erb . in it i've placed the following command :
<%= @text %>
The problem is that when i start the server my app isn't rooted in home and even when i run localhost:3000/pages/home it still doesn't work :
No route matches "/home"
You have created a controller but no view, try these commands
$ rails new myapp
$ cd myapp
$ rails g controller pages index <- this will create a controller **plus** an index view
$ rm public/index.html
now edit routes.rb and add root :to => "pages#index
$ rails s
open http://localhost:3000 and you'll see the new page.
I'm a noob too (I started coding in ruby 2 weeks ago)... I strongly suggest you to get a book, such as Agile Web Development with Rails 4th ed. I covered the book in a week and it gave me a LOT of insight about ruby and rails.
精彩评论