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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:54:42+00:00 2026-06-14T03:54:42+00:00

I have an app which allows users to add recipes and then select their

  • 0

I have an app which allows users to add recipes and then select their favourite recipes to view in their member area, I can select a favourite and i am getting the user_id, recipe_id and giving it a favourite_id.

What I would like to do is output the actual recipe to my view (as a favourite), like dish name, country_of_origin etc. I can do this with an actual recipe but not the favourite.Do i need to use has_many_through for this?

My models look like this

User

has_many :recipes
has_many :favourites

recipe

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

favourites

belongs_to :user
belongs_to :recipe

attr_accessible :user_id, :recipe_id

My controller

  @favourites = current_user.favourites

my link_to post

 <%= link_to "Add to favorites",  {:controller => 'favourites', :action => 'create', :recipe_id => r.id}, {:method => :post } %>

i can list the current users recipes, this is my contoller for this

@recipes = current_user.recipes if current_user.recipes

and then output them to the view like so

 <% @recipes.each do |r| %>
 <tr>
 <td><%= r.dish_name %></td>
 <td><%= r.country_of_origin %></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>

So if i do this in the view

 <li><%= @favourites %></li>

I get this outputted

 <Favourite id: 16, user_id: 8, recipe_id: 21, created_at: "2012-11-07 20:24:39", updated_at: "2012-11-07 20:24:39">]

If i try

 <%= @favourites.dish_name %>

then i get the error undefined method dish_name

How do i get the params of the recipe model to show in the view. I do apologise just cant work it out, which should be really easy i guess?

Any help appreciated

  • 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-14T03:54:43+00:00Added an answer on June 14, 2026 at 3:54 am

    You get undefined dish_name because your Favourite model does not have such attribute.

    @favourites = current_user.favourites returns an array of Favourite objects.

    In your view you would do something like

     <% @favourites.each do |f| %>
       <%= f.recipe %>
     <% end %>
    

    That will display all the recipes your current_user favorites. You could narrow it down to display a specific recipe or what not.

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

Sidebar

Related Questions

I have an app that allows users to add courses to their profile. This
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have a drag and drop application (which allows users to organize their files)
I have a webform that allows users to dynamically add 'sections' (which are divs
I have a simple CoreData app which allows you to add items to a
I have an app which allows users to schedule alarms to sound at certain
I have a flex app which allows user to create some content. this content
I have a Mobile App (iPhone and Android) which allows user to login to
I have a Silveright app that allows users to specify filters on a few

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.