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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:55:50+00:00 2026-06-09T11:55:50+00:00

I have 3 models, User, Army and Engineer. When a User creates an Army

  • 0

I have 3 models, User, Army and Engineer. When a User creates an Army which belongs to them, they can check a checkbox called siege that will create an Engineer which belongs to that Army and User. I have a concern about mass assignment though. The Engineer gets created by my method in my Army model:

attr_reader :siege
after_save :if_siege
private
 def if_siege
   if self.siege
    Engineer.create!( :user_id => self.user.id, :army_id => self.id )
   end
 end
end

But the only way that I know of to have both of the ID’s be assigned is to do this in my Engineer model:

class Engineer
 attr_accessible :user_id, :army_id

This doesn’t seem safe even though engineers can never be created on a form but will automatically be created by a link or checkbox. The ideal is Auto-assign these two attributes like whats done in the controller. e.g.

example = current_user.examples.build(params[:example])

What do you think? Is their an alternative to this design?

Mass assignment is a tricky issue for me…..

  • 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-09T11:55:52+00:00Added an answer on June 9, 2026 at 11:55 am

    What’s wrong with:

    engineer = Engineer.new
    engineer.user_id = self.user.id
    engineer.army_id = self.id
    engineer.save!
    

    You could alternatively specify that you don’t care about the mass assignment issues here only:

    params = { :user_id => self.user.id, :army_id => self.id }
    Engineer.create!(params, without_protection: true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models called User , Activity , and Task and I can do
I have the models User, Post, Comment and Tag. User creates Post. Posts can
I have 2 models: User and Book and a join model ownership which connect
I have three models: User Image Group . User belongs to an image; Group
I have the models User and Group, and the join table Membership which uses
I have those models User, Developer, App, Permission A User can have Default Permision
I have models User and Message. Every user can send messages to other users.
I have three models ( User , Tag , Product ) and they interact
I have two models: User (id) Authentication (id, provider,..) How can I get all
I have two Models called User and Membership. User has_many :memberships Membership belongs_to :user

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.