2

This is a continuation of this: Ruby on rails link_to syntax

I am getting the same error. I tried adding in map.resources :posts to config/routes.rb, but get this error instead

NameError

undefined local variable or method `map' for #<ActionDispatch::Routing::Mapper:0x17dec58>
Rails.root: /Users/Morgan/blog

Application Trace | Framework Trace | Full Trace
config/routes.rb:17:in `block in <top (required)>'
config/routes.rb:1:in `<top (required)>'
This error occurred while loading the following files:
   /Users/Morgan/blog/config/routes.rb
Community
  • 1
  • 1
Morgan Allen
  • 3,291
  • 8
  • 62
  • 86

2 Answers2

2

Rails 3 syntax differs from Rails 2 syntax, which used map.resources :posts.

resources :posts

Most things just exclude the map., like map.root :controller => 'home' becomes:

root :to => 'home#index' # To Syntax: controller#action
Adam Eberlin
  • 14,005
  • 5
  • 37
  • 49
0

In Rails 3+ you don't need to do map.resources :posts. Instead, just do resources :posts. What tutorial are you working from? It may be out of date which is causing your issues. Try using http://guides.rubyonrails.org

Andrew
  • 227,796
  • 193
  • 515
  • 708