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

The Archive Base Latest Questions

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

Admin Main controller: def new @admin = Admin.new @invitation = @admin.invitations.build @admi.user_admin_relationships.build end def

  • 0

Admin Main controller:

def new
  @admin = Admin.new
  @invitation = @admin.invitations.build
  @admi.user_admin_relationships.build
end

def create
  params[:invitation][:sender_id] = current_user.id
  @admin = Admin.new(params[:admin])
  if @admin.save
    redirect_to root_path
  else
    render 'new'
  end
end

Invitation Model

belongs_to :admin
belongs_to :user

Admin Model

has_many :invitations
has_many :user_admin_relationships
has_many :users, :through => :user_admin_relationships

accepts_nested_attributes_for :invitations
accepts_nested_attributes_for :user_admin_relationships, :allow_destroy => true

User Model

has_many :invitations
has_many :user_admin_relationships
has_many :admins, :through => :user_admin_relationships

My forms are nested forms and it works fine saving the fields per the form and items such as created_at and sent_at. However, it does not save the user_id (user_admin join table) and sender_id (invitation table).

I tried adding different permutations to the admin controller, but nothing is working.

Things that does not work:

params[:invitation][:sender_id] = current_user.id

This gives me I have a nil object when I didn’t expect it error.

params[:invitation].merge!(:sender_id = current_user.id)

This give me a “wrong syntax error”

@admin.invitations.build(params[:invitation][:sender_id]) = current_user.id

This gives me unexpected “=” and “expecting keyword end” error

I have tried a bunch of other different permutations as well. Is there something wrong with my associations? How can I update the sender_id in the invitation table and the user_id in the rich join user_admin_relationship table? I know I can do it via a hidden_field, but heard it’s not safe so I don’t want to do that.

  • 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:17:14+00:00Added an answer on May 26, 2026 at 3:17 am

    Use:

    params[:invitation].merge!(:sender_id => current_user.id)
    

    Notice the =>, whereas you just has =. However, in your create action, you are adding that to params[:invitation], but then you aren’t saving that anywhere, so it’s just getting lost. You probably want to use:

    params[:admin][:invitations_attributes][:sender_id]
    

    Also, you are storing sender_id but you don’t have anything to tell your User model to look for sender_id as the foreign key. By default it will look for user_id. You have to add this:

    User: has_many :invitations, :foreign_key => 'sender_id'
    

    and either:

    Invitation: belongs_to :sender, :class_name => "User" # recommended
    # or 
    Invitation: belongs_to :user, :foreign_key => 'sender_id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple controllers one in Areas /Areas/Demo/Admin/AdminController and other in main site /Controller/Admin/AdminController
When I create a page via the CMS (in the admin), everything seems fine
This relates to adding information in a Foreignkey field in the main admin screen.
How to add app item to main django admin site menu without creating any
i create 3 module for my proj like this: application/module/admin application/module/default application/module/error every module
I have created a partial view and I am using it in admin controller's
I'm doing a addin system where the main app loads assemblies Addin1.dll and Addin2.dll
#admin.py class GameListAdmin(admin.ModelAdmin): list_display = ['game', 'position'] ordering = ('position',) class GameAdmin(admin.ModelAdmin): list_display =
In the admin interface and newforms there is the brilliant helper of being able
In my admin view I would like several sub directories for example: admin/users/list.aspx I

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.