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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:44:07+00:00 2026-05-13T12:44:07+00:00

Rails newbie here, trying to get a new controller working. When I try to

  • 0

Rails newbie here, trying to get a new controller working.

When I try to show ann existing instance, I get an undefined method error on a helper method.
Code follows.
Any idea why getRecipes would be undefined?!

Controller:

    def show
       id = params[:id]
       recipe_ids = ConcreteMenu.getRecipes(id)

       respond_to do |format|
          format.html
       end
  end

Model

require 'json/objects'

class ConcreteMenu < ActiveRecord::Base
  has_many :menu_recipes
  has_many :recipes, :through => :menu_recipes

  belongs_to :menu

  def self.getRecipes(id)
      recipes = MenuRecipe.find(:all, :conditions => {:concrete_menu_id => id}, :select => 'id')
   end
end
  • 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-13T12:44:08+00:00Added an answer on May 13, 2026 at 12:44 pm

    It would help if you pasted the error text, because your explanation leaves a lot of possibilities for what could be wrong. BUT, there is an easier way to get what you want. The value of defining “has_many” relationships is that instead of calling a class method and passing the id of a concrete menu to get its associated recipes, you can just do this:

    def show
      @concrete_menu = ConcreteMenu.find(params[:id], :include => :recipes)
    end
    

    Now you’ll have the menu object, and @concrete_menu.recipes returns an array of recipes you need. This feature is already built in, no need to reinvent the wheel.

    Also, I noticed you were attempting to collect id’s in the controller instead of the objects themselves. This suggests that you’re going back and actually retrieving the records in the view itself. This is less efficient, and more difficult to troubleshoot when things go wrong. My example above will do what you need in a better (and more rails-accepted) way.

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

Sidebar

Related Questions

A rails newbie here I have 2 actions in my controller 1) index 2)
Bit of a Rails newbie here so please bear with me. I am trying
As a total newbie I have been trying to get the geoNear command working
I'm a Rails newbie.... Here's what I'm trying to do.... I created a scaffold
Rails 3 newbie here... I'm working to create a devise auth system that like
Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a
I'm a newbie Rails developer who is getting the following error when trying to
I am a complete newbie in working with a Ruby on Rails (RoR) application.
RoR newbie here. Working the play time exercises at the end of Agile Web

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.