0.3576657234101671的未定义方法'call':Float

时间:2018-12-23 23:21:12

标签: ruby-on-rails

这是我的aplication_controller [sic]的配置。

class ApplicationController < ActionController::Base
def disappeareds
  disappeared_id = params[:disappeared_id]
  if(disappeared_id.nil?)
    relation = Relation.where(user_id: current_user.id)
    sorteio = rand.(0...relation.size)
    @disappeared = Disappeared.where(id: relation[sorteio].disappeared_id).take
  else
    @disappeared = Disappeared.where(id: disappeared_id).take
  end
end
end

我遇到此方法错误

NoMethodError - undefined method `call' for 0.3576657234101671:Float:
  app/controllers/application_controller.rb:6:in `disappeareds'
  app/controllers/mains_controller.rb:4:in `index`

2 个答案:

答案 0 :(得分:0)

您多了.

移至

sorteio = rand.(0...relation.size)

sorteio = rand(0...relation.size)

答案 1 :(得分:0)

只去了另一行

TypeError - no implicit conversion from nil to integer: app/controllers/application_controller.rb:7:in消失了   app / controllers / mains_controller.rb:4:in index'