0

In my ruby on rails application I have a show.html.erb page that displays the details of a film, what I want to do is display the dates that film is being shown. In the show.html.erb file I have done this so far:

<% @film.showings.each do |film| %>
    <%= @film.showings.show_date %>         
<% end %>

And in my models I have the associations:

film.rb:

class Film < ActiveRecord::Base
    has_many :showings
    validates :title, presence: true,  length: { minimum: 3 }
end

showing.rb:

class Showing < ActiveRecord::Base
  belongs_to :film
end

In my showings_controller.rb:

class ShowingsController < ApplicationController

    def show
        @showing = Showing.find(params[:id])
    end

end

What am I doing wrong? At the minute I get the error:

NoMethodError in Films#show undefined method show_date for #

What should I be doing?

2
  • Doing that displays the error: undefined method `showings' for #<Showing:0x5b596c0> Commented Jan 21, 2015 at 16:19
  • Which controller does show.html.erb belong? Commented Jan 21, 2015 at 16:21

1 Answer 1

1

I don't know if that's the problem, but the code in show.html.erb is wrong. You are looping over @film's showing, but INSIDE the loop you're stil referring to ALL the showings (@film.showings). Inside, try this:

<% @film.showings.each do |showing| %>
    <%= showing.show_date %>         
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.