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
2
  • Which version of rails are you using? The syntax is different in rails 3. Oct 10, 2011 at 3:07
  • from gem list - rails (3.1.1, 3.0.10) Oct 10, 2011 at 3:09

2 Answers 2

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
0
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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.