-5

wrong number of arguments (given 2, expected 1)

SportsController

class SportsController < ApplicationController
  def index
    @sport = Sport.all
    @events, @errors = Bapi::Inplay.all(query)
  end

  private
    def query
      params[:query, {}]
    end
end

Sport index.html.erb

 <% @sports.each do |sport| %>
   <% @events(:sport_id => sport.id).each_slice(2) do |events| %>

I want send each sport.id to @enevts instance variable


Edited : When send query as hash in SportsController its work!!

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| %>
Qasem
  • 9
  • 1
  • 7

1 Answers1

4

params is a hash and method :[] can accept only 1 argument.

 def query
    params[:query] || {}  # Will return :query part or empty Hash if it has nothing
 end
Nermin
  • 6,118
  • 13
  • 23
  • syntax error, unexpected '(', expecting keyword_end @events(:sport_id => sport.id).each_s... on this line ` <% @events(:sport_id => sport.id).each_slice(2) do |events| %>` – Qasem Aug 29 '18 at 07:57
  • 1
    @Gasem `@events(:sport_id => sport.id)` in your view doesn't make any sense and is incomprehensible to the Ruby interpreter either. You need to fix this, but it's separate problem, so I guess this answer should be accepted. – Marek Lipka Aug 29 '18 at 08:20
  • check this one, it might help you https://stackoverflow.com/questions/24558916/loop-in-ruby-on-rails-html-erb-file – Nermin Aug 29 '18 at 10:32