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 6668757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:04:31+00:00 2026-05-26T03:04:31+00:00

I was trying to play with MongoDb and using the Rails Tutorial to create

  • 0

I was trying to play with MongoDb and using the Rails Tutorial to create users. I’m using the Mongo_mapper gem. I have that all set up but I’m at the point where it seems that ActiveRecord functions/methods don’t seem to work. All my tests work til this point.

I got toggle! to work by adding this to my user model by looking up the toggle source in APIDock

  def toggle!(field)
    send "#{field}=", !self.send("#{field}?")
    save 
  end

But when I try this function to see if the User model boolean of admin

  def admin?
    self.admin
  end

I get this error from my test.

 1) UsersController DELETE 'destroy' as a non-signed-in user should deny access
     Failure/Error: delete :destroy, :id => @user
     NoMethodError:
       undefined method `admin?' for nil:NilClass
     # ./app/controllers/users_controller.rb:66:in `admin_user'
     # ./spec/controllers/users_controller_spec.rb:253:in `block (4 levels) in <top (required)

Here’s what I have for the controller

class UsersController < ApplicationController
  before_filter :authenticate, :only => [:index, :edit, :update]
  before_filter :correct_user, :only => [:edit, :update]
  before_filter :admin_user,   :only => :destroy
.
.
.  

  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User deleted."
    redirect_to users_path
  end

  private

    def authenticate
      deny_access unless signed_in?
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_path) unless current_user?(@user)
    end

    def admin_user
      redirect_to(root_path) unless current_user.admin?
    end

But I do get admin access to work with my admin user and I’m able to delete the user.

<li>
    <%= link_to user.name, user %>
    <% if current_user.admin? %>
        <%= link_to "delete", user, :method => :delete, :confirm => "You sure?",
                                    :title => "Delete #{user.name}" %>
    <% end %>
</li>

Any suggestions on how to fix this as I’m stuck on how to get the app to redirect after deleting a user.

  • 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-05-26T03:04:31+00:00Added an answer on May 26, 2026 at 3:04 am

    Since you dont have a logged in user during that test, current_user is nil, which is exactly the error you are getting.

    So you need to handle the case where current_user is nil:

    def admin_user
      redirect_to(root_path) unless current_user.try(:admin?)
    end
    

    The try method will handle the case where it is called on a nil object. http://api.rubyonrails.org/classes/Object.html#method-i-try

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to play a video that was converted using http://www.mirovideoconverter.com/ to
I am trying to play continuous stream using android mediaplayer.but am not able to
I'm developing a web app using the play! framework and morphia/mongodb. I'm trying to
Hi I am trying to play a video (wmv) file using MediaElement. I have
I am trying to play mp4 video using html5 video tag. But in FF
Hey guys, I've been trying to play with mongoose & node, but I have
I am trying to play and audio file using DirectX dll. Audio.FromFile(Message 1.mp3).Play(); But
I am trying to play audio in a Java applet but it is not
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I'm trying to play only part of a sound using FMOD, say frames 50000-100000

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.