Answer the question
In order to leave comments, you need to log in
How to correctly access data (Rails)?
Hello, I am making a website that will allow you to book a place in a cinema.
There are sessions and there are seats.
Links:
Place belongs_to :session
Session has_many :places
When I reserve a place, the ID of the cinema, the session and the number of the reserved seat itself are stored in the database.
Session controller code
def session_places
@session = Session.find(params[:id])
end
<h1>Show all session places</h1>
<% n = 0 %>
<% @session.number_of_session_places.times do |session| %>
<% n = n + 1 %>
<div class="place_block" style="<% if @session.places.place == n %>background-color: black <% end %>">
<%= n %>
</div>
<% end %>
if @session.place.place
ssession.places.last.place
Answer the question
In order to leave comments, you need to log in
Link specifiedplaces
undefined method `place'.
and you use place
.
It is worth noting that in the console I was able to get to the seat number like this:This is some nonsense.ssession.places.last.place
session.places.last
and there is an instance of the Place class. Do you get place.place ?!
Sessions contain many Locations. Therefore, Session Locations still need to be looped through. Something like:
<% @session.number_of_session_places.times do |session| %>
<% session.places.each do |p| %>
Я место этого сеанса <%= p.place %>
<% end %>
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question