NameError เมื่อเพิ่ม profile route ใน RailsSpace
เมื่อไรที่เจอ error เกี่ยวกับ route ว่า
NameError
undefined local variable or method `show' for main:Object
...
config/routes.rb:38 config/routes.rb:1
และถ้าลองรีเฟรชเบราเซอร์อีกทีหลัง error แรกก็จะเจอ error ที่สอง:
Routing Error
No route matches "/profile/foobar" with {:method => :get}
ให้ลองเช็ค syntax ของ route ของคุณใน routes.rb ดูดีๆ ว่าคุณได้ escape string ชื่อ action ด้วย ” หรือ “” แล้วหรือเปล่า…error นี้จะเกิดถ้าคุณใช้โค้ดผิดๆแบบนี้
map.connect ‘profile/:screen_name’, :controller => ‘profile’, :action => show