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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:12:06+00:00 2026-06-14T05:12:06+00:00

I think I may be missing something here or my understanding of rails model

  • 0

I think I may be missing something here or my understanding of rails model association isnt quite there yet (still learning). I have two models, a recipe and a ingredient. A recipe has many ingredients, and when i fill my form in i want to post recipe and ingredient params to their respective dbs

Recipe Model

 class Recipe < ActiveRecord::Base

 attr_accessible :dish_name, :country_of_origin, :difficulty, :preperation_time
 has_many :ingredients

 end

Ingredients Model

 class Ingredient < ActiveRecord::Base
belongs_to :recipe
attr_accessible :ingredients
end

recipe controller

 def new 

 @recipe = Recipe.new

 end

 def create

 @recipe = Recipe.new(params[:recipe])
 if @recipe.valid?
 @recipe.save
 redirect_to recipes_path, :notice => "Recipe sucessfully created."
 else
 flash.now.alert = "Please ensure all fields are filled in."
 render :new

 end
end

Ingredients Controller

  def new
  @ingredient = recipes.find(params[:recipes_id].ingredients.new
  @recipe_id = params[:recipe_id]
  end

Form

<%= form_for @recipe  do |f| %>

<%= f.label :dish_name, "Dish Name" %>
<%= f.text_field :dish_name, :placeholder => "Enter Dish Name" %>

more fields here(wanted to keep as short as poss)

<%= f.label :ingredients, "Ingredients" %>
<%= f.text_field :ingredients , :class => :ingred, :placeholder => "Enter Ingredient Here" %><br>
<% end %>

Apologies for the size of the code, is anything else needed to see why i cannot create a recipe?

  • 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-14T05:12:07+00:00Added an answer on June 14, 2026 at 5:12 am

    To start with, does your Ingredient model include a foreign key column like “recipe_id”?

    Also, if the ingredients for a given recipe are just stored in a single text string, why not just make that a column in your recipe model instead of creating a second model? Alternatively, if you are going to have multiple ingredients tied to a single recipe, you should look into forms with nested model attributes. There’s a good rails cast on it here.

    Hope this helps.

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

Sidebar

Related Questions

Not sure, but I think this may be a bug? Here is my model:
I think I may be missing something or haven't grasped a fundamental of jQuery.
I think I may have overlooked something here, but I'm not sure why this
I think I may have used a repeater when I should have used something
I think I may be way in over my head here... I'm using a
Maybe I'm totally missing something about even handling in jQuery, but here's my problem.
I think I may be going crazy here... Anyways, I have a DBML with
I think I may be using a wrong window style or something or maybe
I don't know if I'm missing something here, but I am having trouble casting
I've found what I think may be a bug with Ivar and Objective-C runtime.

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.