I just love RoR

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' %>

<%= submit_tag "Create" %> <%= link_to 'Back', {:action => 'list'} %>

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???

On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko[email protected] wrote:

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” %>

Paste in the code for collection_select (and try asking on the rails
list - if this is a rails-specific problem, you’ll get better answers
there).

martin

“<%= text_field ‘movie’, ‘price’ %>

I am so glad to have never started to combine such template language
with code (or rather, have stopped doing so after writing a lot php many
years ago)

It would just confuse my poor brain. How can anyone appreciate this
syntax noise?

Martin DeMello wrote:

On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko[email protected] wrote:

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” %>

Paste in the code for collection_select (and try asking on the rails
list - if this is a rails-specific problem, you’ll get better answers
there).

And while you’re there, please ask them to improve Rails error messages
so that if there’s an error in a helper method, you get a pointer to the
helper method line not the line in the template :slight_smile:

You haven’t declared @genres in your controller under new. You’ve
declared
@movie and @subjects but not @genres - declare it here and you’ll fix
your
error.