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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:06:06+00:00 2026-06-17T06:06:06+00:00

In my app, i have admin subfolder, and controller there, and method: class Admin::UserGroupsController

  • 0

In my app, i have admin subfolder, and controller there, and method:

class Admin::UserGroupsController < ApplicationController
  def index
    @pre_usergroups = UserGroup.all
    @user_groups = Kaminari.paginate_array(@pre_usergroups).page(params[:page]).per(50)
    render :layout => 'admin'
  end
end

route:

namespace :admin do
resources :user_groups
end

and model (not in subdirectory admin):

class UserGroup < ActiveRecord::Base
  attr_accessible :group_id, :user_id
  belongs_to :group
  belongs_to :user
  validates :user_id, :presence => {:message =>  I18n.t(:user_not_chosen)}
  validates :group_id, :presence => {:message =>  I18n.t(:group_not_chosen)}


  def get_group_name(id)
    @gr = Group.find(id)
    @gr.name
  end

  def get_user_name(id)
    @user = User.find(id)
    @user.email
  end
end

Also i didn’t see validation message’s and it’s working…. it skip validation:

and view:

%table.table.table-striped
  %tr
    %th
      Название группы:
    %th
      Пользователь:  
  -@user_groups.each do |u|
    %tr  
      %td
        = u.get_group_name(group_id)
      %td
        = u.user_id

But why i get

 undefined local variable or method `group_id' for #<#<Class:0xb352734>:0xab437dc>

So i didn’t go to method in model…
How can i access model method?

  • 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-17T06:06:07+00:00Added an answer on June 17, 2026 at 6:06 am

    as stated in the error group_id is not defined which is true.
    You should be calling it as follows:

    = u.get_group_name(u.group_id)

    because group_id is an attribute of the UserGroup object

    However, I don’t see why you are making the methods get_group_name and get_user_name, why don’t you just use u.group.name and u.user.email?

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

Sidebar

Related Questions

Lets assume I have created a facebook app.So all those who(Admin) have facebook fan
I'm working on an app in CodeIgniter, and I want to have admin pages
I have a C# winforms app with a form for user preferences. An admin
In my django app i have the admin site and I am trying to
I'm developing an app with CakePHP and in my app I have an admin
I have datastore admin enabled in one app and the backup system seems to
I have an admin activity in an app which will allow him or her
I have an admin app that runs with elevated privileges and I need it
I'm using Django 1.2.4. I have an admin class for a model that has
In DjangoBook, it says that the every books app should have its own admin.py.

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.