Search code examples
ruby-on-railsredmine-plugins

NoMethodError when calling a helper method in a view


I'm working on a simple timesheet plugin for Redmine, all was going well until I tried to use helpers.

The 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

In the view I have helper "timesheet"

But I've also tried

helper :timesheet

and

helper TimesheetHelper

In the first line of index.rhtml it says

<h2><%= l :timesheet_for %> <% first_day_of_week @week %> <%=l :and %>  
<% last_day_of_week @week %></h2>

and rails throws a NoMethodError on first_day_of_week @week

Is there something I'm missing?


Solution

  • Your method is

    def first_day_in_week(datum)
    

    not

    def first_day_of_week(datum)
    

    The name is not the same, so the method is not found ^^