Warum erhalte ich die Fehlermeldung "undefined method "anzeigen"?

In meine Ruby on Rails-Anwendung, mit der ich versuche, die Anzeige einer über drei drop-down-Menüs in der _form.html-Code.erb, die gerendert werden aus der Datei _booking_lookup.html-Code.erb und erhält dort die Daten aus dem drop-down-Menü-Methoden in den Modellen.

_form.html-Code.erb:

<%= render(:partial => '/booking_lookup', :locals=> {:film => @film = Film.all, :showings => @showings = Showing.all, :seats => @seats = Seat.all, :my_path => '/films/booking_lookup' }) %>

_booking_lookup.html-Code.erb:

<%= form_tag my_path, :method=>'post', :multipart => true do %>
<%= select_tag ('title_id'), 
    options_from_collection_for_select(@films, :id, :title_info, 0 ),
    :prompt => "Film" %>

<%= select_tag ('showings_id'), 
    options_from_collection_for_select(@showings, :id, :showing_times, 0 ),
    :prompt => "Showings" %> 

<%= select_tag ('seat_id'), 
    options_from_collection_for_select(@seats, :id, :seats_available, 0 ),
    :prompt => "Seats" %> 

<%= submit_tag 'Search' %>

film.rb:

class Film < ActiveRecord::Base

has_many :showings
belongs_to :certificate
belongs_to :category

def title_info
     "#{title}"
end
end

Sitz.rb:

class Seat < ActiveRecord::Base
belongs_to :screen
has_many :bookings

def seats_available
    "#{row_letter}#{row_number}"
end
end

zeigen.rb:

 class Showing < ActiveRecord::Base
  belongs_to :film
  has_many :bookings
  belongs_to :screen

    def showing_times
        "#{show_date.strftime("%e %b %Y")} @ #{show_time.strftime("%H:%M")}"
    end
end

Aber aus irgendeinem Grund mit der Zeile: <%= select_tag ('title_id'),
options_from_collection_for_select(@films, :id, :title_info, 0 ),
:prompt => "Film" %>
bekomme ich die Fehlermeldung:

NoMethodError in Bookings#new 
undefined method `map' for nil:NilClass

Dem seltsamen Teil ist, dass ich viel von diesem code wo anders, ich habe eine _multi_search.html-Code.erb form:

 <%= form_tag my_path, :method=>'post', :multipart => true do %>
 <!--  Genre: -->
 Search By:
 <%= select_tag ('cat_id'), 
    options_from_collection_for_select(@categories, :id, :category_info, 0 ),
    :prompt => "Genre" %>

<%= select_tag ('cert_id'), 
    options_from_collection_for_select(@certificates, :id, :certificate_info, 0 ),
    :prompt => "Age Rating" %> 

<%= text_field_tag :search_string, nil, placeholder: "ACTOR" %>
or
<%= select_tag ('title_id'), 
    options_from_collection_for_select(@films, :id, :title_info, 0 ),
    :prompt => "Film" %>
<%= submit_tag 'Search' %>
<% end %>

Und ist in der Anwendung verwendet.html-Code.erb:

<%= render(:partial => '/multi_search', :locals=> {:categories => @categories = existing_genres, :certificates => @certificates = Certificate.all, :films => @films = Film.all, :my_path => '/films/multi_find' }) %>

Und das funktioniert auch.

Was mache ich falsch?

  • Haben Sie überprüft, wenn @Filme ist nil?
  • Nein habe ich nicht, aber ich bin sicher, es ist nicht null. Was ist komisch ist, ich habe etwas ähnliches arbeiten, wo sonst und das funktioniert auch - ich werde auch diese in der ursprünglichen Frage.
  • @films ist nil - du bist Einstellung @film = Film.all, nicht @films = Film.all.
InformationsquelleAutor | 2015-02-20
Schreibe einen Kommentar