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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:59:04+00:00 2026-06-07T14:59:04+00:00

I’m using simple_form, and I just want to create association between categories and articles

  • 0

I’m using simple_form, and I just want to create association between categories and articles using categorization table.

But I have this error:
Can’t mass-assign protected attributes: category_ids.
app/controllers/articles_controller.rb:36:in `update’

articles_controller.rb

def update
    @article = Article.find(params[:id])
      if @article.update_attributes(params[:article]) ---line with the problem
        flash[:success] = "Статья обновлена"
        redirect_to @article
      else
        render :edit
      end
end

article.rb

has_many :categorizations
has_many :categories, through: :categorizations

category.rb

has_many :categorizations
has_many :articles, through: :categorizations

categorization.rb

belongs_to :article
belongs_to :category

categorization has article_id and category_id fields.

My _form.html.erb

<%= simple_form_for @article, html: { class: "form-horizontal", multipart: true } do |f| %>
  <%= f.error_notification %> 
  <%= f.input :title %>
  <%= f.association :categories %>
  <%= f.input :teaser %>
  <%= f.input :body %>
  <%= f.input :published %>
 <% if @article.published? %>
   <%= f.button :submit, value: "Внести изменения" %>
 <% else %>
   <%= f.button :submit, value: "Опубликовать" %>
  <% end %>
<% 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-07T14:59:06+00:00Added an answer on June 7, 2026 at 2:59 pm

    do you have attr_accessible in article.rb?

    if so add

         attr_accessible :title, :category_ids
    

    Also make sure you really want this for all forms… If not add this:

      attr_accessible :title, :category_ids, :as => :admin
    

    then

    @article = Article.new
    @article.assign_attributes({ :category_ids => [1,2], :title => 'hello' })
    @article.category_ids # => []
    @article.title # => 'hello'
    
    @article.assign_attributes({ :category_ids => [1,2], :title => 'hello' }, :as => :admin)
    @article.category_ids # => [1,2]
    @article.title # => 'hello'
    @article.save
    

    or

    @article = Article.new({ :category_ids => [1,2], :title => 'hello' })
    @article.category_ids # => []
    @article.title # => 'hello'
    
    @article = Article.new({ :category_ids => [1,2], :title => 'hello' }, :as => :admin)
    @article.category_ids # => [1,2]
    @article.title # => 'hello'
    @article.save
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to

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.