I really dont know what to do now my dealine is ahead having an error…
NoMethodError in Movie#new
Showing movie/new.html.erb where line #8 raised:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
Extracted source (around line #8):
5:
Price:
6: <%= text_field ‘movie’, ‘price’ %>
7:
Genre:
8: <%= collection_select(:movie,:genre_id,@genres,:id,:title) %>
9:
Description
10: <%= text_area ‘movie’, ‘description’ %>
11: <%= submit_tag “Create” %>
view code new.rhtml
Add new movie
<%= form_tag :action => 'create' %>Title: <%= text_field 'movie', 'title' %>
Price: <%= text_field 'movie', 'price' %>
Genre: <%= collection_select(:movie,:genre_id,@genres,:id,:title) %>
Description
<%= text_area 'movie', 'description' %>
db migrate for genre
class CreateGenres < ActiveRecord::Migration
def self.up
create_table :genres do |t|
t.column :name, :string
end
Genre.create :name => "HORROR"
Genre.create :name => "ACTION"
Genre.create :name => "DRAMA"
Genre.create :name => "COMEDY"
Genre.create :name => "DOCUMENTARY"
end
def self.down
drop_table :genres
end
end
db migrate for movie
class CreateMovies < ActiveRecord::Migration
def self.up
create_table :movies do |t|
t.column :title, :string, :limit => 32, :null => false
t.column :price, :float
t.column :genre_id, :integer
t.column :description, :text
t.column :created_at, :timestamp
end
end
def self.down
drop_table :movies
end
end
movie model code
class MovieController < ApplicationController
def list
@movies = Movie.find(:all)
end
def showA
@movie = Movie.find(params[:id])
end
def new
@movie = Movie.new
@subjects = Movie.find(:all)
end
def create
@movie = Movie.new(params[:movie])
if @movie.save
redirect_to :action => ‘list’
else
@genres = Genre.find(:all)
render :action => ‘new’
end
end
def edit
@movie = Movie.find(params[:id])
@genres = Genre.find(:all)
end
def update
@movie = Movie.find(params[:id])
if @movie.update_attributes(params[:movie])
redirect_to :action => ‘show’, :id => @movie
else
@genres = Genre.find(:all)
render :action => ‘edit’
end
end
def delete
Movie.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end
Pls somo0ne out there …help???