Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:28:39+00:00 2026-06-03T06:28:39+00:00

Essentially I have an app usong Devise, i’ve a user model and an agenda

  • 0

Essentially I have an app usong Devise, i’ve a user model and an agenda model. Agenda ‘belongs_to’ user and user ‘has_many” agenda, these are my db relationships. I can fire up IRB and get db data correctly
user = User.first
user.agendas
and I will get a list of all posts that belong to that user
My problem occurs upon signing in, the user is redirected to home#index but I get a NoMethodError in Home#index undefined method `agendas’ for nil:NilClass
I’m sure i’m missing something. Do I need an index method in my agenda controller also?
..app/views/home/index.html.erb

<h3>Home</h3>
<div class="row">
    <div class="span8">
        <% if @user.agendas.any? %>
        <h3>Agendas</h3>
        <ol class="agendas">
            <%= render @agendas %>
        </ol>
        <% end %>
    </div>
</div>

my home_controller.rb

class HomeController < ApplicationController
  before_filter :authenticate_user!

  def index
    @agendas = current_user.agendas.paginate(page: params[:page])
  end

My agenda controller just has a create and destroy stub for future code.
its model /agenda.rb

class Agenda < ActiveRecord::Base
  attr_accessible :title
  belongs_to :user

  validates :title, presence: true, length: { maximum: 140 }
  validates :user_id, presence: true

  default_scope order: 'agendas.created_at DESC'
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:28:40+00:00Added an answer on June 3, 2026 at 6:28 am

    Your error is coming from this:

    <% if @user.agendas.any? %>
    

    and the error says that @user is nil. Your controller says:

    def index
      @agendas = ...
    end
    

    I don’t see @user being assigned a value in there. I don’t think your authenticate_user! filter is setting @user either. So you could do this:

    def index
      @user    = current_user
      @agendas = @user.agendas.paginate(page: params[:page])
    end
    

    And then:

    <% if @user.agendas.any? %>
      <h3>Agendas</h3>
      <ol class="agendas">
        <%= render @agendas %>
      </ol>
    <% end %>
    

    You could also access current_user directly in your ERB:

    <% if current_user.agendas.any? %>
      <h3>Agendas</h3>
      <ol class="agendas">
        <%= render @agendas %>
      </ol>
    <% end %>
    

    But keep in mind that you’ve already gone to the trouble of computing @agendas so why not just look at that and leave your controller alone?

    <% if @agendas.present? %>
      <h3>Agendas</h3>
      <ol class="agendas">
        <%= render @agendas %>
      </ol>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an internal asp.net forms app where one page is essentially a WYSIWYG
I have a largish complex app around 27k lines. Its essentially a rule drive
I have a SharePoint web part (essentially just a Hello World app) that I
I'm using active admin for my rails app. I have a customer model which
I have an HTML5 iPad app that works offline. The app essentially consists of
Heres the problem. I have an app that is essentially an image gallery, it
I have a webview app tool, which essentially consists of the webview and two
In my iPhone app, I have a view controller with two views (essentially, a
Essentially I have a method of a class called killProgram, which is intended to
Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.