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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:34:33+00:00 2026-06-14T02:34:33+00:00

I have a simple app where you can upload recipes I have just integrated

  • 0

I have a simple app where you can upload recipes

I have just integrated the gem terrarum to give me all the countries of the world within my country model. I have a relationship where a recipe has_one country and a country belongs to recipe. I am using nested forms from ryan bates and have had no problem getting information to show from my ingredients model and preparation model. But i cannot get the country name to save in the table or show in the view (though this is caused by not saving to model)

Code is as follows

Form

<%= f.label :country_id, "Country Of Origin" %>
<%= f.collection_select(:country_id, Country.all, :id, :name, :prompt => 'Please select country') %>

View

<% @recipes.each do |r| %>
<tr>
<td><%= r.dish_name %></td>
<td><%= r.country.name %></td>
<td><%= r.difficulty %></td>
<td><%= r.preperation_time %></td>
<td><%= ingredient_names(r.ingredients) %></td>
<td><%= preperation_steps(r.preperations) %></td>
<td><%= image_tag r.avatar.url(:thumb)%></td>
</tr>

Helper

def preperation_steps(preperations)
if preperations
  preperation_array = preperations.map {|pre| pre.prep_steps}
  preperation_array.join("\n")
end
end

def country_name(country)
if country
  country_array = country.map {|c| c.country_name}
  country_array.join("\n")
end
end
end

I have included my preparation helper as this works, so surely my country_name helper mirrors this? or do i not need to put a helper in for this?

recipe controller

def new 

@recipes = current_user.recipes if current_user.recipes #show recipes if the user has any recipes
 @favourites = current_user.favourites

end

recipe model

  belongs_to :user
  belongs_to :country
  has_many :ingredients 
  has_many :preperations
  has_many :favourites

  attr_accessible :dish_name, :difficulty, :preperation_time, :ingredients_attributes, :preperations_attributes, :country_id, :avatar:preperations_attributes, :country_id, :avatar

  has_attached_file :avatar, :styles => {  :medium => "300x300>", :thumb => "100x100>" } 

  accepts_nested_attributes_for :ingredients, :preperations

  scope :top_countries, order("country_of_origin DESC")

if anyone can help it would be much appreciated

Thanks

  • 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-14T02:34:34+00:00Added an answer on June 14, 2026 at 2:34 am

    In this code I see two mistakes:

    1. Recipe should belong_to :country. Don’t use has_one here. The foreign key country_id should be in the recipes table.
    2. @recipe.build_country is not necessary. You already have a list of countries. You should only use build_country if you are planning to add a new country to the list of countries, which you are not in this case.

    Also, you don’t need fields_for. You can just do:

    <%= f.label :country_id, "Country Of Origin" %>
    <%= f.collection_select(:country_id, Country.all, :id, :name, :prompt => 'Please select country') %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple app where you can login it looks like this: {{#view
So I have a simple web app where I can create a user (UserModel)
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I have an app that basically can be used to download, upload, and manage
The usual case. I have a simple app that will allow people to upload
I have a simple bottle.py app that let's me upload files. Now since those
This is a real newbie question. I have simple app that selects a picture
I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*
I have a simple app with a full screen UIWebView. This contains HTML generated
I have one simple app that suppose to get information from user and send

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.