Topic: NilClass

for some reason my class returns NilClass

but i have no idea where to start to debug

Re: NilClass

The log file is your friend. You can use logger.debug commands to send output to tjhe log file then you can see what is happening.

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: NilClass

i am sure if this is what you are looking for


Started GET "/user" for 127.0.0.1 at 2012-04-30 22:13:16 -0400
Processing by UserController#index as HTML
  Rendered user/index.html.erb within layouts/user (2.5ms)
Completed 200 OK in 6ms (Views: 6.3ms | ActiveRecord: 0.0ms)


Started GET "/assets/styles/table.css?v=1" for 127.0.0.1 at 2012-04-30 22:13:17 -0400
Served asset /styles/table.css - 304 Not Modified (0ms)


Started GET "/assets/libs/jquery-1.7.2.min.js" for 127.0.0.1 at 2012-04-30 22:13:17 -0400
Served asset /libs/jquery-1.7.2.min.js - 304 Not Modified (0ms)

Started GET "/assets/libs/jquery.tablesorter.min.js" for 127.0.0.1 at 2012-04-30 22:13:17 -0400
Served asset /libs/jquery.tablesorter.min.js - 304 Not Modified (0ms)


Started GET "/assets/Entypo/entypo-webfont.woff" for 127.0.0.1 at 2012-04-30 22:13:17 -0400
Served asset /Entypo/entypo-webfont.woff - 304 Not Modified (0ms)


Started GET "/assets//assets/standard/sprites.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /assets/standard/sprites.png - 404 Not Found (7ms)

ActionController::RoutingError (No route matches [GET] "/assets/assets/standard/sprites.png"):
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/debugger.rb:20:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/moiseszaragoza/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/moiseszaragoza/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/moiseszaragoza/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'


  Rendered /Users/moiseszaragoza/.rvm/gems/ruby-1.9.2-p290@newoncall/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.6ms)


Started GET "/assets/user.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /user.png - 304 Not Modified (0ms)


Started GET "/assets/effects/glow.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /effects/glow.png - 304 Not Modified (0ms)


Started GET "/assets/standard/sprites.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /standard/sprites.png - 304 Not Modified (0ms)


Started GET "/assets/textures/grid.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /textures/grid.png - 304 Not Modified (0ms)


Started GET "/assets/standard/shortcuts.png" for 127.0.0.1 at 2012-04-30 22:13:18 -0400
Served asset /standard/shortcuts.png - 304 Not Modified (0ms)

Last edited by moiseszaragoza (2012-04-30 22:17:15)

Re: NilClass

All I can see is that Rails can't find the image 'sprites.png':

/assets/standard/sprites.png - 404 Not Found (7ms)

Where the idea of NilClass comes from?

Re: NilClass

yea, but i dont think that a image not found be the problem for a NilClass

What i know it's not much

i am trying to create a user class
files :
app/views/user/index.html.erb

<%= @user.class %>

app/models/user.rb

class User < ActiveRecord::Base
  attr_accessible :accountName, :active, :code, :firstName, :lastName, :password, :salt, :username, :usertype
end

app/controllers/user_controller.rb

class UserController < ApplicationController
  layout 'user'
  def index
  end
  def show
  end

  def create
  end

end

Re: NilClass

What does the exact error say when you try to go to Users#Index? It will probably be helpful to include the full trace I think.

If it's what I'm thinking, I sometimes get a similar error when I try to access an attribute that's not in the db, usually because of a typo. For example, on my user model, I was recently trying to display a user's name ( @user.name ), but it wasn't working because I forgot to make the migration for that column in the db (didn't have my coffee that day I guess).

Change is a vector. You can have all the change in the world, but if it doesn't go in the right direction, what good is it? | techonamission.com

Re: NilClass

The funny thing is that there is no error there is just a NilClass


if i do <%= @user.name %>

NoMethodError in User#index

undefined method `name' for nil:NilClass



NoMethodError in User#index

Showing /Users/moiseszaragoza/Sites/blog/app/views/user/index.html.erb where line #47 raised:

Re: NilClass

Of course, it's because you are trying to acces to the '@user' instance variable in the 'index' view but it is nil, - @user does not exist in your index action in the controller:

def index
end

You should initialize @user in the action that renders the corresponding view, all the instance variable are available OOB in the view to be rendered.

And you are not creating a User class like you are saying:

i am trying to create a user class
files :
app/views/user/index.html.erb

<%= @user.class %>

Last edited by Javix (2012-05-02 04:21:29)