NoMethodError quando si chiama un metodo di supporto in una vista
-
19-09-2019 - |
Domanda
Sto lavorando su un semplice plugin timesheet per Redmine, tutto andava bene fino a quando ho cercato di utilizzare aiutanti.
L'helper:
module TimesheetHelper
def first_day_in_week(datum)
return unless datum.kind_of? Date
datum - datum.wday
end
def last_day_in_week(datum)
return unless datum.kind_of? Date
datum + (6 - datum.wday)
end
end
Nella vista ho aiuto "timesheet"
Ma ho anche provato
helper :timesheet
e
helper TimesheetHelper
Nella prima riga del index.rhtml si dice
<h2><%= l :timesheet_for %> <% first_day_of_week @week %> <%=l :and %>
<% last_day_of_week @week %></h2>
e rotaie getta un NoMethodError su first_day_of_week @week
C'è qualcosa che mi manca?
Soluzione
Il tuo metodo è
def first_day_in_week(datum)
non
def first_day_of_week(datum)
Il nome non è lo stesso, in modo che il metodo non viene trovato ^^
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow