NoMethodError in Devise::Sessions#new

200 views
Skip to first unread message

huon sothon

unread,
Jul 20, 2014, 10:04:20 PM7/20/14
to rubyonra...@googlegroups.com
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!
 

Walter Lee Davis

unread,
Jul 21, 2014, 8:53:35 AM7/21/14
to rubyonra...@googlegroups.com
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

>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/aebbb661-5553-480b-b0f4-3e6a8907381c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

tamouse pontiki

unread,
Jul 22, 2014, 10:59:14 PM7/22/14
to rubyonra...@googlegroups.com
On Mon, Jul 21, 2014 at 7:52 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:
On Jul 20, 2014, at 10:04 PM, huon sothon wrote:
> 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>
Reply all
Reply to author
Forward
0 new messages