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: <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" %>

view code new.rhtml

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

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

--
Posted via http://www.ruby-forum.com/\.

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

···

On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko<ouikoto@yahoo.com> wrote:

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

"<%= 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?

···

--
Posted via http://www.ruby-forum.com/.

Martin DeMello wrote:

···

On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko<ouikoto@yahoo.com> wrote:

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

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:

--
Posted via http://www.ruby-forum.com/\.

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.

···

On Mon, Jul 13, 2009 at 7:43 AM, Marc Heiler <shevegen@linuxmail.org> wrote:

"<%= 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?
--
Posted via http://www.ruby-forum.com/\.