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!

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!

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

> 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: <li><a href="/">Home</a></li>
> 26: <li><a href="#">Products</a>
> 27: <ul class="dropdown-menu">
> 28: <% @categories.each do |category| %>
> 29: <li><a href="#"><%= category.category_name %></a>

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

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.

<opinion type="personal">
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.
</opinion>