# I just love RoR

**URL:** <https://www.ruby-forum.com/t/i-just-love-ror/171998>\
**Category:** Ruby\
**Created:** [July 13, 2009, 8:57am UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998 "2009-07-13T08:57:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ouikoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@ouikoto](https://www.ruby-forum.com/u/ouikoto)\
**Post date:** [July 13, 2009, 8:57am UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998/1 "2009-07-13T08:57:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ouikoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@ouikoto](https://www.ruby-forum.com/u/ouikoto)\
**Post date:** [July 13, 2009, 9:23am UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998/2 "2009-07-13T09:23:24Z")

</div>

On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ouikoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@ouikoto](https://www.ruby-forum.com/u/ouikoto)\
**Post date:** [July 13, 2009, 1:43pm UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998/3 "2009-07-13T13:43:35Z")

</div>

“\<%= 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?

---

<div class="post-metadata">

**Author:** ![ouikoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@ouikoto](https://www.ruby-forum.com/u/ouikoto)\
**Post date:** [July 13, 2009, 2:00pm UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998/4 "2009-07-13T14:00:31Z")

</div>

Martin DeMello wrote:

> On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂

---

<div class="post-metadata">

**Author:** ![ouikoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e68b1a/32.png) [@ouikoto](https://www.ruby-forum.com/u/ouikoto)\
**Post date:** [July 13, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/i-just-love-ror/171998/5 "2009-07-13T14:05:40Z")

</div>

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.
