Tik’s Blog

ร้อยแปดพันเก้า

NameError เมื่อเพิ่ม profile route ใน RailsSpace

leave a comment »

เมื่อไรที่เจอ 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

Written by sukita

กุมภาพันธ์ 7, 2009 ที่ 10:54 pm

บันทึกโพสใน Programming

Tagged with

ใส่ความเห็น