Rails新手在這裏,試圖讓一個新的控制器工作。未定義的方法錯誤,但我定義了它!
當我嘗試顯示ann存在的實例時,我得到一個輔助方法未定義的方法錯誤。 代碼如下。 任何想法爲什麼getRecipes將不確定?!
控制器:
def show
id = params[:id]
recipe_ids = ConcreteMenu.getRecipes(id)
respond_to do |format|
format.html
end
end
型號
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
我強烈建議重構到'def self.foo'的首選Ruby風格,而不是'def self.getFoo'。 – Eli 2010-01-26 18:48:59
另一件事,在ruby methods_are_named_like_this。你來自Java嗎? – jonnii 2010-01-26 18:58:11
你可以發佈你的堆棧跟蹤嗎?我會說這個問題在你發佈的代碼之外。另外,我同意Eli的觀點,並補充說Ruby的約定是snake_case,而不是camelCase。 – Ben 2010-01-26 19:00:12