Ruby on Rails
Thursday, July 7, 2016
How did you setup your model relationship between users and appointments
On Thu, Jul 7, 2016 at 1:42 PM, Ruth Stephenson <lists@ruby-forum.com> wrote:
Thanks for your help, however it wont' work.
I put
<%= link_to 'My
appointment',current_user.appointments.order(:appointment_date).last%>
ERROR:
SQLite3::SQLException: no such column: appointments.appointment_date:
SELECT "appointments".* FROM "appointments" WHERE
"appointments"."user_id" = ? ORDER BY "appointments"."appointment_date"
DESC LIMIT 1
Walter Davis wrote in post #1184502:
>> %>
>> Appointment belongs to user
>> user has many appointments
>
> This is why the link doesn't work. A user (current_user) does not have
> _an_ appointment, she has _many_ appointments. If you want the latest
> one, then use
>
> current_user.appointments.order(:appointment_date).last if
> current_user.appointments.any?
>
> You could put that in a helper so it doesn't make your views so
> ungainly.
>
> Walter
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fcc891ac7f93f17fa89bf8c8ba4ff4fd%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHewxcGe8EDVXNPyJ4rAPM5S0jNRG-jRGadDYBNPxMrK9Y3sUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment