错误的参数数量(给定2个,预期为1个)
SportsController
class SportsController < ApplicationController
def index
@sport = Sport.all
@events, @errors = Bapi::Inplay.all(query)
end
private
def query
params[:query, {}]
end
end
体育index.html.erb
<% @sports.each do |sport| %>
<% @events(:sport_id => sport.id).each_slice(2) do |events| %>
我想将每个sport.id
发送到@enevts
实例变量
编辑:
当在SportsController
中将查询作为哈希发送时!
class SportsController < ApplicationController
def index
@sport = Sport.all
query = {:sport_id => 1}
@events, @errors = Bapi::Inplay.all(query)
end
private
def query
params[:query, {}]
end
end
Index.html.erb
<% @sports.each do |sport| %>
<% @events.each_slice(2) do |events| %>
答案 0 :(得分:4)
params
是一个哈希,方法:[]
只能接受1个参数。
def query
params[:query] || {} # Will return :query part or empty Hash if it has nothing
end