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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:33:02+00:00 2026-05-29T11:33:02+00:00

I’ve spent hours on this one. I’m trying to use Ryan Bate’s nested_form_for plugin

  • 0

I’ve spent hours on this one. I’m trying to use Ryan Bate’s nested_form_for
plugin in rails 3.2 though I don’t think it’s related to my issue. I tried
taking it out and I still get the same issue.

When I hit organizations/:org_id/publications/new I see the form to add a new
publication correctly. However, when I submit (with or without correct data) it
I get an unknown attribute: publications_attributes error. I’m sure there’s
something wrong with the way I’m building the related object(s) in the create
method. Any ideas?

models/organization.rb

class Organization < ActiveRecord::Base
  attr_accessible :name,
                  :publications_attributes, # fk, nested form
  has_many :publications
  accepts_nested_attributes_for :publications,
                                :allow_destroy => true

models/publication.rb

class Publication < ActiveRecord::Base
  attr_accessible :link,
                  :organization_id
  belongs_to :organization
  validates :link,
            :presence => true,
end

controllers/publications_controller.rb

class PublicationsController < ApplicationController

  def new
    @organization = current_user.organizations.first
    @organization.publications.build
  end

  def create
    @organization = current_user.organizations.first
    @organization.publications.build(params[:organization])
    if @organization.save
      flash[:notice] = "Successfully created publications"
      redirect_to @organization
    else
      render :action => 'new'
    end
  end
end

routes.rb

resources :organizations do
  resources :publications,  :only => [:new, :create]
end

views/publications/new.html.erb

<%= nested_form_for @organization, :html => { :novalidate => 'novalidate' },
                                   :method => :post,
                                   :url => organization_publications_path, do |f| %>

  <%= render 'shared/error_messages', :object => f.object %>

  <%= f.fields_for :publications do |publication_form| %>
    <%= render :partial => 'publications/form', :locals => { :f => publication_form } %>
  <% end %>
  <%= f.link_to_add "Add", :publications %>

  <%= render :partial => 'shared/submit', :locals => { :text => 'Create', :f => f } %>
<% end %>

views/publications/_form.html.erb

<div class="field">
  <%= f.label :link %>
  <%= f.text_field :link %>
</div>
<%= f.link_to_remove "Remove" %>

The submitted hash looks like this:

Parameters: {
    "utf8"=>"✓",
    "authenticity_token"=>"rhW/m8mnulZMmW7gkLYxOT8RWYoQc8eYdp2hOXkqHPU=",
    "organization"=>{
        "publications_attributes"=>{
            "0"=>{
                    "link"=>"fdsfdsfs"
            }
        }
    },
    "commit"=>"Create",
    "organization_id"=>"53"
}
  • 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-29T11:33:07+00:00Added an answer on May 29, 2026 at 11:33 am

    Ok, ignore my previous answer. This is a little different than what I have done in the past, but since the organization already exists you can just call update_attributes on that. Rails (3.2 at least) will loop through all the publication_attributes and add new ones or update existing ones. In the create method try this…

    if @organization.update_attributes(params[:organization])
      flash[:notice] = "Successfully created publications"
      redirect_to @organization
    else
      render :action => 'new'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build

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.