ฉันกำลังพยายามทำความเข้าใจการกำหนดเส้นทางราง ฉันได้อ่านคู่มือ Rails แล้ว แต่ฉันยังคงสับสนอยู่ ตัวอย่างเช่น ฉันมี post_controller พร้อมการดำเนินการ Rails crud ทั้งหมดดังนี้:
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
ดังที่ฉันเห็นจากด้านบนมีเพียง index, new, edit and show
การกระทำเท่านั้นที่มีชื่อเส้นทางทางด้านซ้าย ตัวอย่างเช่น การกระทำ index
มีชื่อเส้นทาง posts
และฉันจะได้รับ URL เป็น posts_path
และฉันสามารถใช้มันในแท็กลิงค์ได้ดังนี้
<a href="/th<%= posts_path %>">here</a>
แต่ไม่มีชื่อเส้นทางสำหรับการสร้าง อัปเดต และทำลายการดำเนินการ ดังนั้นฉันจะรับ url สำหรับสร้างการกระทำในกรณีนี้สำหรับลิงค์ด้านล่างได้อย่างไร
<a href="/th<%= ..... link to create action of post controller %>">here</a>