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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:23:02+00:00 2026-05-13T08:23:02+00:00

has_many build method, Rails Was my last question. It now works: no errors. The

  • 0

has_many build method, Rails

Was my last question. It now works: no errors.
The new problem is that the new unit conversion doesn’t associate with an ingredient ID. I thought this was “just supposed to work” from the build method?

Unit Conversion controller:

 def new
  @ingredient = Ingredient.find(params[:ingredient_id])    
  @unit_conversion = @ingredient.unit_conversions.build
end

def create
  @ingredient = Ingredient.find(params[:ingredient_id])    
  @unit_conversion = @ingredient.unit_conversions.build(params[:unit_conversion])

  if @unit_conversion.save
    flash[:notice] = "Successfully created unit conversion."
    redirect_to ingredient_unit_conversions_url(@ingredient)
  else
    render :action => 'new'
  end
end

Unit Conversion Model:

class UnitConversion < ActiveRecord::Base
  belongs_to :ingredient
end

Ingredient Model:

class Ingredient < ActiveRecord::Base
  belongs_to :unit
  has_many :unit_conversions
end

Thanks for the help, I’m finding a rough learning curve today 🙂

EDIT:
One more important thing..
new.html.erb

<h1> New Derived Unit </h1>
<% form_for([@ingredient, @unit_conversion]) do |f| %>
        <% f.error_messages %>

        <p>
            <%= f.label :name %>
            <%= f.text_field :name%>
        </p>
        <p>
            <%= f.label :conversionToBase%>
            <%= f.text_field :conversionToBase%>
        </p>
        <p>
            <%= f.submit "Create" %>
        </p>
    <% end %>
<% link_to 'Back', url_for( :controller => 'ingredients', :action => 'show', :id => @ingredient)%>
  • 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-13T08:23:02+00:00Added an answer on May 13, 2026 at 8:23 am

    Make sure that you have form_for [@ingredient, @unit_conversion] in your form.

    new.html.erb

    <% title "New Unit Conversion" %>
    <%= render :partial => 'form' %>
    <p><%= link_to "Back to List", ingredient_unit_conversions_path(@ingredient) %></p>
    

    _form.html.erb

    <% form_for [@ingredient, @unit_conversion] do |f| %>
      <%= f.error_messages %>
      <p>
      ... fields here
      </p>
      <p><%= f.submit "Submit" %></p>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a User model that :has_many other models like Documents, Videos, Posts
I'm trying to Unit Test a class that has many internal functions. These obviously
An article has many articles that it refers to and many other articles can
I have an application that has many different types of objects that each persist
I was reading about self-referential has_many :through data situations today, because I'm trying to
I have an existing app that has many, many models. I'd like to log
My app has many controls on its surface, and more are added dynamically at
Our Development environment has many layers and is complicated to replicate or even backup
I have 3 tables (archive has many sections, section (may) belong to many archives):
I have a class which has many small functions. By small functions, I mean

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.