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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:40:34+00:00 2026-05-26T15:40:34+00:00

I’m using ryan bates’ plugin nested_form and i have been trying to write my

  • 0

I’m using ryan bates’ plugin nested_form and i have been trying to write my form for a has_many :through relationship.

I have 3 models:

Profile
  has_many :memberships
  has_many :organizations, :through => :memberships
  accepts_attributes_for :organizations
  attr_accessible :organization_attribtues
Membership
  has_many :profiles
  has_many :organizations
Organization
  has_many :memberships
  has_many :profiles, :though => :memberships

The below form is for the profile but with the organization nested inside of it. I can create information about the organization by doing f.fields_for :organizations, but then I’m unclear on how to update information specific to their membership in the organization. Specifically, there is a title attribute on the membership table ( i commented it out below because it throws an error undefined method `title’ for Organisation). Any help would be so very appreciated! Thanks.

= f.fields_for :organisations do |org|
    = org.input :name, :label => "<strong>Name of the Organization</strong>"
    = org.input :title, :label => "Your role"
    = org.input :description, :as => :text, :label => "Description of the organization",
  • 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-26T15:40:35+00:00Added an answer on May 26, 2026 at 3:40 pm

    As I saw here on StackOverflow with another question, I need to nest the hm => t like so

    = f.fields_for :memberships do |mem|
    = mem.fields_for :organisation do |org|
      .row
        .span5.org_name
          = org.input :name, :label => "<strong>Name of the Organization</strong>"
        .span5
          = mem.input :title, :label => "<strong>Title in the Organization</strong>"
      .row
        .span5
          = mem.input :starting_year, :label => "<strong>Starting Year</strong>"
        .span5
          = mem.input :ending_year, :label => "<strong>Ending Year</strong>"
      .row
        .span10
          = org.text_area :description, :label => "<strong>Description of Organisation</strong>"
    = mem.link_to_remove "Remove this oranisation"
    = f.link_to_add "Add an organisation", :memberships
    

    BUt with Ryan Bates’ plugin, the association to memberships organisations is not built as far as i can tell, so i created a new method like this:

         = f.link_to_add_hmt "Add an organisation", :organisation, :memberships
    

    And then I pretty much just copied Ryan Bates’ plugin verbatim adding a new parameter adding 2 lines below

    def link_to_add_hmt(*args, &block)
      options = args.extract_options!.symbolize_keys
      association = args.pop
      association_two = args.pop
      options[:class] = [options[:class], "add_nested_fields"].compact.join(" ")
      options["data-association"] = association
      args << (options.delete(:href) || "javascript:void(0)")
      args << options
      @fields ||= {}
      @template.after_nested_form(association) do
        model_object = object.class.reflect_on_association(association).klass.new
        model_object.send(:"build_#{association_two}")
        output = %Q[<div id="#{association}_fields_blueprint" style="display: none">].html_safe
        output << fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
        output.safe_concat('</div>')
        output
      end 
      @template.link_to(*args, &block)
    end 
    

    Look for the references to “association_two”. This works great!

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.