Topic: Beginners question - problem with the linkage of routes and actions
since a few weeks I try to get familiar with Ruby and Ruby on rails.
After trying some first basic tests with plain Ruby I now switch over to Rails.
While working through several tutorials I often encountered problems with the routes in Rails and it connection to corresponding actions - the fact that lots of tutorials are not for my Rails3 but for Rails2 doesn't make it any better
I will show up my current issue:
In a tutorial I try to make some kind of forum. The tutorial uses the nifty-generators and sqlite3 so I also did this.
I went through the model definition, database and data association creation with success, created the layout via rails generate nifty:layout.
Then it was about editing the routes.rb.
The tutorial proposed an entry
map.root :controller => "forums"
but I figured out that map.root is old Rails2 style and outdated.
I changed to entry to
root :controller => 'forums', :action => 'index'
From my understanding this should jump into the forums_controllers.rb to the index-action whenever the root of the webserver is adressed, right? (so, http://localhost:3000 should trigger index within forums_controllers.rb , right?).
The corresponding entry in the forums_controller.rb looks like this:
class ForumsController < ApplicationController def index @forums = Forum.all end
After starting the webserver and typing in localhost:3000 it tells me the following error:
NoMethodError in ForumsController#index undefined method `all' for Forum:Module ... app/controllers/forums_controller.rb:3:in `index'
Changing the line in routes.rb to
root :to => 'forums#index'
does not do anything else and the same error appears.
What did I forget to change/to add? Is there more to edit I don't know yet?