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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:27:08+00:00 2026-05-30T05:27:08+00:00

I’m trying to create a form_for using the following fields. However, some of the

  • 0

I’m trying to create a form_for using the following fields. However, some of the fields correspond to one model, the RecipeIngredient class (model), whereas the bottom fields correspond to the Recipe class (model).

  <%= form_for(:recipe_and_ingredients, :url => {:action => 'create'}) do |f| %>

<!-- RecipeIngredient classs -->
<table>
<tr>
 <td>4</td>
 <td><%= f.text_field(:quantity) %></td>
 <td><%= f.text_field(:weight) %></td>
 <td><%= f.text_field(:units) %></td>
</tr>
</table> 


<!-- Recipe class -->
<table summary="Recipe form fields">
  <tr>
    <th>Recipe Name</th>
    <td><%= f.text_field(:recipe_name) %></td>
    <th>Total Grams</th>
    <td><%= f.text_field(:total_grams) %></td>
  </tr>
</table>

<div class="form-buttons">
  <%= submit_tag("Create Recipe") %>
</div>

<% end %>

However, in my controller:

 # Instantiate a new object using form parameters
  @recipe = Recipe.new(params[:recipe_and_ingredients])
  @ingredient = RecipeIngredient.new(params[:recipe_and_ingredients])

I get this error when I submit the form

  unknown attribute: quantity

I know this is because the Recipe model/class/table/whatever does not have a quantity column; that is a column within RecipeIngredient (which is supposed to be a join table between Recipe and some other table if that is relevant). When I submit the params however, how do I differentiate, in the code, which parameters belong to which class?

  • 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-30T05:27:10+00:00Added an answer on May 30, 2026 at 5:27 am

    use
    In the model: accepts_nested_attributes_for
    In the controller: Nothing
    In the routes: Nothing
    In the view, at the point where you want the ‘nested’ fields, use f.fields_for :other_model do |inner| and then you can use inner.inner_field_name. I think inner would be ingredient in your case, if that is what RecipieIngredient is and you renamed it to ingredient. If receipieIngredient is actually a more complex join table redo as needed.

    See more at http://railscasts.com/episodes/196-nested-model-form-part-1

    I would name the entities ‘recipies’ and ‘ingredients’ and then have a form for a recipie that has fields_for :ingredients do |i|.

    If you want Ingredient has_many recipies and Recipie has_many ingredients, you can do that too with has_many_through in both of the models pointing to a join model IngredientRecipie which belongs to_both recipie and ingredient but that doesn’t affect the form. Those relationships are used to retrieve data.

    Note that if you have these has_many through you can use simple_form to just maintain the relationship with checkboxes for the relationships and no other code to write other than saving the data with one save.

    Update:

    Recipie (model)
    Recipie has_many :recipie_ingredients
    Recipie has many :ingredients, :through => :recipie_ingredients
    
    Ingredient (model)
    Recipie has_many :recipie_ingredients
    Recipie has many :ingredients, :through => :recipie_ingredients
    
    RecipieIngredient (model)
    belongs_to :recipies
    belongs_to :ingredients
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.