Why do I get the error `undefined method 'map'`?
drop-down-menu, ruby, ruby-on-rails, ruby-on-rails-3
Solution
It looks like `@films` is nil. Try setting `@films = Film.all` (instead of `@film = Film.all`) in _form.html.erb.
Update:
I would recommend moving the queries to the controller action. In the Model-View-Controller pattern, Controllers should be asking Models for data, not Views.
# BookingLookupController
def new
@films = Film.all
@showings = Showing.all
@seats = Seat.all
end
You can then reference the instance variables in the view.
<%= render partial: '/booking_lookup', locals: {films: @films, showings: @showings, seats: @seats, my_path: '/films/booking_lookup' } %>
Problem
In my Ruby on Rails application I am trying to display a three drop down menus in the _form.html.erb which are rendered from the file _booking_lookup.html.erb and get there data from the drop down menu methods in the models. _form.html.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.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 ``` seat.rb: ``` class Seat < ActiveRecord::Base belongs_to :screen has_many :bookings def seats_available "#{row_letter}#{row_number}" end end ``` showing.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 ``` But for some reason with the line: `<%= select_tag ('title_id'), options_from_collection_for_select(@films, :id, :title_info, 0 ), :prompt => "Film" %>` I get the error: ``` NoMethodError in Bookings#new undefined method `map' for nil:NilClass ``` The weird part is that I am using a lot of this code else where, I have a _multi_search.html.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 %> ``` And is used in the application.html.erb: `<%= render(:partial => '/multi_search', :locals=> {:categories => @categories = existing_genres, :certificates => @certificates = Certificate.all, :films => @films = Film.all, :my_path => '/films/multi_find' }) %>` And that works fine. What am I doing wrong?