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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:15:54+00:00 2026-06-05T08:15:54+00:00

I was following a railscast trying to create a add link to add a

  • 0

I was following a railscast trying to create a add link to add a value connected with many to many associtation. the only difference that I have implemented the many to many using a model and not

has_and_belongs_to_many. 

and it doesnt work so well .
(The presenetation is fine but the add button fails. )

here is my code

File:ingredient_recipe.rb

class IngredientRecipe < ActiveRecord::Base
  attr_accessible :created_at, :ingredient_id, :order, :recipe_id
  belongs_to :recipe
  belongs_to :ingredient
end

File:ingredient.rb

class Ingredient < ActiveRecord::Base
 has_many :ingredient_recipes
 has_many :recipes, :through => :ingredient_recipes
 ...

File:recipes.rb

class Recipe < ActiveRecord::Base
 has_many :ingredient_recipes
 has_many :ingredients, :through => :ingredient_recipes
 ...

in the ui

 <%= link_to_add_fields "Add", f, :ingredient_recipes %>

the method is defined

def link_to_add_fields(name, f, association)
 new_object = f.object.class.reflect_on_association(association).klass.new
 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
   render(association.to_s.singularize + "_fields", :f => builder)
 end
 link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")
end

The Problem

the
render(association.to_s.singularize + “_fields”, :f => builder)
displays

<%= f.text_field :name%>
<%= f.hidden_field :_destroy%>
<%= link_to “x”,””, class: “remove_fields”%>

and prints an error

 ActionView::Template::Error (undefined method `name' for #<IngredientRecipe:0x6393ee8>):

any ideas?

  • 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-05T08:15:56+00:00Added an answer on June 5, 2026 at 8:15 am

    Not entirely sure if this is it, but since it’s trying to call name on the ingredient_recipe object, have you tried changing the symbol passed in the method?

     <%= link_to_add_fields "Add", f, :ingredients %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a many-to-many model, following the example in this great railscast My model
I'm following Ryan Bates' declarative authorization railscast. I'm trying to add functionality for author
I'm following Railscast 88 to create a dynamic dependent dropdown menu. http://railscasts.com/episodes/88-dynamic-select-menus I'm rendering
I'm trying to set up a Twitter login using Devise/OmniAuth, following the latest RailsCast
I have a few models that contain static data, and I'm trying to cache
I have followed the following railscast about adding pdfkit to an application, and I
I'm following railscast and have followed the instructions exactly. I've even used net.tutsplus's faye.ru
I'm trying to integrate stripe into my app. I'm following a Railscast (#288) but
I'm following http://railscasts.com/episodes/102-auto-complete-association Everything seems fine. I'm trying to create an invoice and also
I'm following part of this Railscast and trying to load a static file using

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.