Answer the question
In order to leave comments, you need to log in
How to access model objects?
Hello, tell me how to deal with calls to model objects. I read the documentation, but I can not find the answer to this question.
I pull the last user in the console - u = User.last
Then I pull all the places from the table (places) that this user booked -u.places
[#<Place id: 3, cinema_id: 1, film_session_id: 1, place_number: 10, status: false, created_at: "2016-04-15 11:02:40", updated_at: "2016-04-15 11:02:40", user_id: 1>, ...
<FilmSession id: 6, cinema_id: 3, session_name: "deadpool", number_of_session_place: 100, created_at: "2016-04-21 12:40:42", updated_at: "2016-04-21 12:40:42", user_id: 1>
has_many :cinemas
has_many :film_sessions
has_many :places
belongs_to :cinema
has_many :places, :dependent => :destroy
belongs_to :user
has_many :film_sessions
belongs_to :cinema
belongs_to :user
has_many :film_sessions
belongs_to :user
<% @user.places.each do |place| %>
<tr>
<td><%= place.place_number %></td>
<td><%= place.cinema.cinema_name %></td>
<% p = place.film_session_id %>
<% f = FilmSession.find(id = p) %>
<td><%= f.session_name %></td>
</tr>
<% end %>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question