I just love RoR

Discussion in 'Ruby' started by Luis Teko, Jul 13, 2009.

  1. Luis Teko

    Luis Teko Guest

    >>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/.
     
    Luis Teko, Jul 13, 2009
    #1
    1. Advertising

  2. On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko<> 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" %>



    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
     
    Martin DeMello, Jul 13, 2009
    #2
    1. Advertising

  3. Luis Teko

    Marc Heiler Guest

    "<%= 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/.
     
    Marc Heiler, Jul 13, 2009
    #3
  4. Martin DeMello wrote:
    > On Mon, Jul 13, 2009 at 12:28 PM, Luis Teko<> 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 :)

    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Jul 13, 2009
    #4
  5. [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.



    On Mon, Jul 13, 2009 at 7:43 AM, Marc Heiler <> 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/.
    >
    >
     
    Gregory Mazurek, Jul 13, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Travis Newbury

    I just love you guys....

    Travis Newbury, Jul 23, 2005, in forum: HTML
    Replies:
    4
    Views:
    478
    Travis Newbury
    Jul 23, 2005
  2. walterbyrd
    Replies:
    1
    Views:
    393
    Damjan
    Apr 10, 2006
  3. Lawrence D'Oliveiro

    Don't you just love writing this sort of thing :)

    Lawrence D'Oliveiro, Dec 4, 2008, in forum: Python
    Replies:
    40
    Views:
    1,100
    Tim Rowe
    Dec 10, 2008
  4. Love love love

    , Jun 3, 2009, in forum: C++
    Replies:
    0
    Views:
    462
  5. t3chn0n3rd

    I just love RUBY programming

    t3chn0n3rd, Mar 2, 2008, in forum: Ruby
    Replies:
    1
    Views:
    125
Loading...

Share This Page