-2

我有一个这样的控制器动作:

def index    
    @start_limit = 0    
    @last_limit = 5    
    @start = params[:start]    
    @last = params[:next]    
    if @last    
      @start_limit = (@Start_limit) + (@last)  
      @last_limit = (@last_limit) + (@last)  
    elsif @start  
      @start_limit = (@start_limit) - (@start)  
      @last_limit = (@last_limit) - (@start)  
    else  
      # do nothing  
    end  
end  

当我正在执行包含此类控制器操作的程序时,会发生以下错误:
undefined method '+' for nil:NilClass. 我需要一个解决方案。
我是RoR的新手,我欢迎任何人的建议。

4

3 回答 3

2

Ruby 是一种区分大小写的语言,因此@start_limit@Start_limit第 7 行,大写字母 s)是两个不同的变量。将其更改为小写,它应该可以工作。

于 2012-06-01T08:57:42.943 回答
2

代替:

@start_limit = (@Start_limit) + (@last)

和:

@start_limit = (@start_limit) + (@last)

于 2012-06-01T08:57:43.257 回答
1

改变

if @last    
      @start_limit = (@Start_limit) + (@last)  
      @last_limit = (@last_limit) + (@last)  
    elsif @start  
      @start_limit = (@start_limit) - (@start)  
      @last_limit = (@last_limit) - (@start)  
    else 

if @last    
      @start_limit = (@start_limit) + (@last)  
      @last_limit = (@last_limit) + (@last)  
    elsif @start  
      @start_limit = (@start_limit) - (@start)  
      @last_limit = (@last_limit) - (@start)  
    else 
于 2014-06-27T09:10:13.023 回答