NoMethodError in Devise::Sessions#new

Hi everybody
i am new developer in ROR. now i have one question to ask?
i am using devise for authentication.it is work very well .but when i
select data (category or sub_category) from database in
app/views/layouts/application.html.erb and then i click sign_in it show
errors as shown below:

NoMethodError in Devise::Sessions#new

Showing C:/railsapp/facepro/app/views/layouts/application.html.erb
where
line #28 raised:

undefined method `each’ for nil:NilClass

Extracted source (around line #28):

25
26
27
28
29
30
31

    <li><a href="/">Home</a></li>
 <li><a href="#">Products</a>
   <ul class="dropdown-menu">
     <% @categories.each do |category| %>
   <li><a href="#"><%= category.category_name %></a>
            <ul class="dropdown-menu">

please help me!

On Jul 20, 2014, at 10:04 PM, huon sothon wrote:

   <li><a href="/">Home</a></li>

     <ul class="dropdown-menu">

please help me!

I’m not sure what Devise has to do with this specifically. Have you
looked to see what if anything is in the @categories variable? It sounds
as though it’s nil, by the error. It should be at least an array if you
want each to work. What does this view’s controller method look like?
(Copy and paste, please.)

Walter

On Mon, Jul 21, 2014 at 7:52 AM, Walter Lee D. [email protected]
wrote:

undefined method `each’ for nil:NilClass
Extracted source (around line #28):

please.)

Walter

The error precisely points to line 28, and the object that is receiving
the
.each method is @categories, which means it is nil. Where has
@categories
been set? As this bit of code is in the application layout
(app/views/layouts/application.html.erb), it should fail on every page
that
uses that layout. You state:

when i select data (category or sub_category) from database in
app/views/layouts/application.html.erb

However, @categories is not selecting any data from the database
there,
@categories should already have been assigned data, probably inside
app/controllers/application_controller.rb so it’s available to all
controllers (and their views).

It has nothing to do with devise, as Walter states.

It is quite tempting to start a project including devise, but really you should work on getting the core of your product working first. This is especially true when you're starting out, as you've seen you don't quite have a grasp on what everything is doing yet. (You will though!) Keep it as simple as possible; you can add multiuser abilities later.