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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:43:50+00:00 2026-06-04T15:43:50+00:00

Mostly my entries in seeds.rb are simple, like this: User.create!( name: Peter admin: false;

  • 0

Mostly my entries in seeds.rb are simple, like this:

User.create!(
name: "Peter"
admin: false;
# etc.
)

If I get the “Can’t mass-assign protected attributes” error, I make a small change in the model, in this case user.rb:

attr_accessible: name, admin

So far so good. But how am I supposed to seed entries into tables generated by a rails gem which adds another engine to my app? Forem, for example. And I’m sure there are others.

I have added these entries to my seeds.rb file:

Forem::Category.create!(
name: "cat1"
)

Forem::Forum.create!(
title: "forum1",
description: "forum1 description",
category_id: 1
)

Forem::Topic.create!(
forum_id: 1,
user_id: 1,
subject: 'topic1',
locked: false,
pinned: false,
hidden: false,
)

Category and Forum are generated, Topic is not:

Can't mass-assign protected attributes: forum_id, user_id, locked, pinned, hidden

If I had a topic.rb model, I would know what to do. But I don’t have it. Forem is an engine and I don’t know of a way to make some attributes of model topic.rb visible.

I know that this line in application.rb:

config.active_record.whitelist_attributes = true

enables the protection against mass assignment. Disabling it leaves a huge security hole, so it’s not an option. And disabling it didn’t allow me to seed into topics table anyway.

I’ve also tried to use fixtures. I added this to my seeds.rb file:

require 'active_record/fixtures'
Fixtures.create_fixtures("#{Rails.root}/test/fixtures", "topics.yml")

test/topics.yml:

one:
  id: 1
  forum_id: 1
  user_id: 1
  subject: "topic1"
  created_at: 2012-05-19 19:54:19
  updated_at: 2012-05-19 19:54:20
  locked: false
  pinned: false
  hidden: false
  last_post_at: 2012-05-19 19:54:21
  state: "open"
  views_count: 3

Error I get is – uninitialized constant Fixtures

What’s wrong with my seeds.rb and fixture? Or should I use a migration?

  • 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-04T15:43:51+00:00Added an answer on June 4, 2026 at 3:43 pm

    Disabling it leaves a huge security hole, so it’s not an option`

    Nope, it’s not a huge security hole. This is a controversial debate, but attr_accessible (and variants) are (in my and a lot of others opinion) not a good solution to the problem that is preventing users to create/update objects/attributes they should not. Put another way, attr_accessible is a model solution to a controller issue. Because that is the job of the controller to make sure that the data is cleaned and usable, to check wether the current user is allowed to do such things, etc.

    So what I’d do would be to remove all references to attr_accessible and set whitelist_attributes to false.

    Then it’s up to you to filter your params in your controllers. You could do as done in this gist or use rails/strong_parameters, or any other way that might please you.

    After that you would no longer have these issues while seeding

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

Sidebar

Related Questions

I mostly develop using C#, but I think this question might be suitable for
This question is mostly academic. I ask out of curiosity, not because this poses
I mostly write in C but am using Java for this project. I want
I am mostly wondering how to organize things like modal windows, and dynamic pages
I'm mostly just curious if this is a bad idea for some reason. I'm
My application is mostly organised in layers so I found that something like the
I'm mostly convinced of the benefits of unit testing, and I would like to
This is mostly a theoretical question I'm just very curious about. (I'm not trying
This may be a very simple question, but I haven't found an answer to
We have an application that stores a sparse matrix. This matrix has entries that

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.