2014-09-24 67 views
0

我读过这个线程helper方法:Rails optional argument,并试图实现它在Rails 4助手功能,看起来像这样:轨道所需的参数

# this is in the application helper 
def getRank(team_id, week = '') 
    if week.empty? 
    week = Settings.pluck(:week) # grab the current week 
    end 
    # do some stuff to get the current team's rank 
end 

当我把这个控制台,但是我仍然得到:

> helper.getRank(5) 
ArgumentError: wrong number of arguments (1 for 2) 
from /home/rails_testing/app/helpers/application_helper.rb:24:in `getRank' 

我错过了什么?

+0

你确实有一些事情在周后=这不是一个评论,对吧? – nPn 2014-09-24 02:07:01

+0

@nPn它是'week =''' - 与我引用的示例中的相同。 – user101289 2014-09-24 02:08:01

+0

我的意思是星期=#grap本周 – nPn 2014-09-24 02:08:35

回答

3

rails console在启动时读取您的应用程序代码。因此,您需要在更改代码后重新启动您的rails console

0

每次在代码中进行更改时,您必须重新启动您的rails console

您可以使用此reload!命令重新启动控制台。