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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:21:00+00:00 2026-06-14T09:21:00+00:00

My application has Dwellings and Roomies . I am building some authentication into the

  • 0

My application has Dwellings and Roomies. I am building some authentication into the Dwelling view – only users who are roomies of the current dwelling should be able to view certain data – all other users will see a different view.

To enable this, I have created an is_roomie? method in the Users Controller. The method looks like this:

## is_roomie? method in Users_Controller.rb ##

def is_roomie?
roomie_ids = []
@dwelling.roomies.each do |r|
  roomies_ids << r.id
end
roomie_ids.include?(current_user.id)
end 

I call this method in the Dwelling view as follows:

## show.html.erb (Dwelling) ##
....
<% if current_user && current_user.is_roomie? %>
....

When I loaded the page after implementing this, I get the following NoMethoderror:

NoMethodError in Dwellings#show

Showing >/Volumes/UserData/Users/jraczak/Desktop/Everything/rails_projects/Roomie/roomie/app/views/dwellings/show.html.erb where line #5 raised:

undefined method `is_roomie?’ for #User:0x00000102db4608>

For some background, I did try this as a Dwelling method and moved this into the User model to no avail. Thanks in advance for any and all insight!

  • 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-14T09:21:01+00:00Added an answer on June 14, 2026 at 9:21 am

    current_user is a User object, not a UsersController object, so you cannot call the method you’ve defined on that object. When you think about it in this context, you’ll see that you should define this method on User.

    Try something like this in app/model/user.rb:

    class User < ActiveRecord::Base
      # ...
      def roomie?(dwelling)
        dwelling.roomies.include?(self)
      end
    end
    

    Looking at this, though, we can improve the code by moving it into the Dwelling class in app/models/dwelling.rb:

    class Dwelling < ActiveRecord::Base
      # ...
      def roomie?(user)
        roomies.include?(user)
      end
    end
    

    You would then use this in the view with:

    <% if current_user && @dwelling.roomie?(current_user) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application has Users and Dwellings . When a user creates a dwelling ,
My application has a simple data model with 70 read-only records grouped into six
My application has two layouts A and B. In A a user chooses some
My application has only one service class (not activity) in which I keep value
My application has several workers (working on different things as different processes) and some
My application has an sqlite DB, where some of the fields are null or
My application has multiple view controllers. In my VehicleListController I am saving the data
My application has some parabolic partial differential equations...which are inter-related and use some variables
Our application has about 30 page. Does it make sense create all view page
Application has 7-8 activities, so I have create an application with some background music

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.