문제

Ok, say you have this:

match "tutor_appointments/new_appt" => "tutor_appointments#new_appt"

How do I create a link_to path from it?

Would it be something like this: (it doesn't work, btw)

<%= link_to "New Appointments", controller:tutor_appointments, method:new_appt %>

I'm always confused on routing stuff when it comes to figuring out how to do link_to link.

I do understand that tutor_appointments is the controller and new_appt is the method.

도움이 되었습니까?

해결책

Ideally, you would name the route:

http://guides.rubyonrails.org/routing.html#naming-routes

And then you can refer to the route by that name.

eg. if you had:

match "tutor_appointments/new_appt" => "tutor_appointments#new_appt", as: 'new_appointment'

Then you could do:

link_to 'New Appointments', new_appointment_path

However, in this case it sounds like what you actually want is resource routing:

http://guides.rubyonrails.org/routing.html#resources-on-the-web

And you want a 'new' action for your 'tutor_appointments' resource.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top