【发布时间】:2014-04-25 23:18:06
【问题描述】:
我正在尝试从我的模型中调用一个方法:
<p>
<strong>Holidays this year:</strong>
<%= Country.all_holidays_in(2014) %>
</p>
我也尝试将我的方法放入我的控制器中,但它不起作用。 但我只是得到这个错误:
NoMethodError in Countries#show
Showing C:/xampp/htdocs/fluxcapacitor/app/views/countries/show.html.erb where line #15 raised:
undefined method `all_holidays_in' for Country(id: integer, name: string, countrycode: string):Class
这是我的模型:
class Country < ActiveRecord::Base
has_and_belongs_to_many :groups
validates :name, presence: true
validates :countrycode, presence: true
def all_holidays_in(y)
from = Date.civil(y,1,1)
to = Date.civil(y,12,31)
return Holidays.between(from, to, self.countrycode)
end
end
我怎么称呼它的任何想法?
【问题讨论】:
标签: ruby-on-rails ruby methods model call