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

  • Home
  • SEARCH
  • 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 6375605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:38:13+00:00 2026-05-25T01:38:13+00:00

I have a website where people can comment and each comment has a category

  • 0

I have a website where people can comment and each comment has a category they can pick from the a drop down menue.
In my comment modal I have

belongs_to :category

and I have a category_id in the comment table.

when a user submit the comments in the params I get
params[:comment] = {“locale”=>”en”, “body”=>”fds”, “category_id” =>2, “from_identifier”=>2130706433, “from_type”=>”ip”, “cookie_user_token”=>”130784267178572”, “user_id”=>3}

which is exactly what I want. However when I do

Comment.create(params[:comment])

I get

#<Comment id: nil, from_type: "ip", from_identifier: 2130706433, cookie_user_token: 130784267178572, body: "fds", locale: "en", positive_vote_count: 0, adjusted_positive_vote_count: 0.0, negative_vote_count: 0, adjusted_negative_vote_count: 0.0, flag_vote_count: 0, adjusted_flag_vote_count: 0.0, impression_count: 0, visit_count: 0, rank: 137.0, created_at: nil, updated_at: nil, user_id: 3, category_id: nil>

as you can see category_id is nil.

User model has the same relationship with active record, so I don’t know why that gets saved and category_id doesn’t.

Right now I do

comm = Comment.create(params[:comment])
comm.category_id = params[:comment][:category_id]

Any idea why, and what I should do to avoid the hack up there?

  • 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-25T01:38:14+00:00Added an answer on May 25, 2026 at 1:38 am

    Have you used attr_protected or attr_accessible to prevent mass assignment to category_id?

    If so, that’s the problem.

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

Sidebar

Related Questions

I have a website where people can contact each other, and quite often people
I have a website where people can add content and when they type in
I have a website where people can upload documents, and view them later at
I have an website where people can place a vote like this: http://mysite.com/vote/25 This
I have a website where people can upload 30+mb of data in a single
I have a website that lets people view rows in a table (each row
Currently, I have a website that people can open up during a certain team's
I have a website which is displayed to visitors via a kiosk. People can
i have a website where people can leave comments on some articles. \ what
I have a website where only a couple of people can access it, so

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.