小编Pat*_*t R的帖子

(未定义的方法`+ @'表示[]:数组)

当我尝试遍历一个对象数组时,我收到一条非常奇怪的错误消息.错误是

NoMethodError (undefined method `+@' for []:Array):
Run Code Online (Sandbox Code Playgroud)

这是该循环的代码.

#go through items and see if there are any corresponding offers 
    #All matches are stored in a hash
    items.each do |itemsi|
        bestoffer = -1
        matchescounter++ #matchescounter only get incredmented when all the offers have been taken care of
        offers.each do |offs|
        if itemsi.togive.to_str == offs.totake.to_str
            if offs.togive.to_int > bestoffer
                bestoffer = offs.togive.to_int
                matches[matchescounter].store(itemi, offer)         
            end#if
        end#if
        end#offers loop
    end#items loop
Run Code Online (Sandbox Code Playgroud)

我的代码中没有+ @.奇怪

arrays ruby-on-rails

3
推荐指数
1
解决办法
4358
查看次数

从模型类调用控制器方法

我有一个简单的问题.是否可以从模型中调用控制器方法?如果有可能,我似乎无法弄明白.我应该只是从模型返回控制器而不是尝试直接调用方法吗?谢谢,帕特

model-view-controller ruby-on-rails

1
推荐指数
1
解决办法
3026
查看次数