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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:09:08+00:00 2026-06-02T16:09:08+00:00

When i try to submit the form below i get this error WARNING: Can’t

  • 0

When i try to submit the form below i get this error WARNING: Can't mass-assign protected attributes: sub_category.I have tried to go over previous asked related questions here on stackoverflow and seems like i am in the right track ,but for some reason i am still getting the same error,what am i doing wrong?.I have included all the info below, thank you in advance.

View/form

 <%= form_for @ip ,:url=>{:action =>"create"} do |f| %>
 <%=f.text_field   :email %>
 <% f.text_field :ip_address %>
      <%= f.fields_for :sub_category do |s| %>
      <%=s.text_field :name%>
      <%end%>
 <%=f.submit "submit" %>
 <%end%>

Controller

def create
@ips=Ip.new(params[:ip])
    @ip=@ips.sub_categories.build 
if @ip.save
    redirect_to :controller=>"home" ,:action=>"index"
else
    render 'index'
end     

Models

class Ip < ActiveRecord::Base
has_many :sub_categories ,:through=>:ip_subs
has_many :ip_subs
accepts_nested_attributes_for :sub_categories 
attr_accessible :sub_categories_attributes,:ip_address,:email,:ip_count
end

class SubCategory < ActiveRecord::Base
has_many :ip ,:through=>:ip_subs
has_many :ip_subs
end

class IpSub < ActiveRecord::Base
belongs_to :ip
belongs_to :sub_category
end
  • 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-02T16:09:09+00:00Added an answer on June 2, 2026 at 4:09 pm

    You should use f.fields_for :sub_categories (association name).

    And don’t forget to build association before render the form:

    # in controller
    def new
      @ip = Ip.new
      @ip.sub_categories.build
    end
    

    rubyonrails api :: fields_for

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

Sidebar

Related Questions

I'm getting this error when I try to submit my form (/POSTS/SHOW): RuntimeError in
How can I submit jQuery form object (not ajax)? I try form.submit() and it
I am getting a conversion error every time I try to submit a date
Try as I might, I can't get a JNLP file to run locally (via
Try running this in a .VBS file MsgBox(545.14-544.94) You get a neat little answer
I am trying to use the form below to submit 4 images to a
Edit:I added this if (isset($_POST['delete']) && isset($_POST['checkbox'])) (get from an answer below but it
if you try my code below you can see that the background color is
I would like to display an ajax loader icon when user try to submit
Try as I might I cannot get my head around what the IteratorIterator class

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.