I just love RoR


L

Luis Teko

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: <p><label for="movie_price">Price</label>:
6: <%= text_field 'movie', 'price' %></p>
7: <p><label for="movie_genre">Genre</label>:
8: <%= collection_select:)movie,:genre_id,@genres,:id,:title) %></p>
9: <p><label for="movie_description">Description</label><br/>
10: <%= text_area 'movie', 'description' %></p>
<h1>Add new movie</h1>
<%= form_tag :action => 'create' %>
<p><label for="movie_title">Title</label>:
<%= text_field 'movie', 'title' %></p>
<p><label for="movie_price">Price</label>:
<%= text_field 'movie', 'price' %></p>
<p><label for="movie_genre">Genre</label>:
<%= collection_select:)movie,:genre_id,@genres,:id,:title) %></p>
<p><label for="movie_description">Description</label><br/>
<%= text_area 'movie', 'description' %></p>
<%= submit_tag "Create" %>
<%= link_to 'Back', {:action => 'list'} %>


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


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





 
Ad

Advertisements

M

Martin DeMello

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: <p><label for="movie_price">Price</label>:
6: <%= text_field 'movie', 'price' %></p>
7: <p><label for="movie_genre">Genre</label>:
8: <%= collection_select:)movie,:genre_id,@genres,:id,:title) %></p>
9: <p><label for="movie_description">Description</label><br/>
10: <%= text_area 'movie', 'description' %></p>
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
 
M

Marc Heiler

"<%= text_field 'movie', 'price' %></p>"

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

Brian Candler

Martin said:
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 :)
 
Ad

Advertisements

G

Gregory Mazurek

[Note: parts of this message were removed to make it a legal post.]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top