错误的参数数量 - 在initialize方法中

Ved*_*Ved 1 ruby

我无法弄清楚这个非常简单的错误:

xyz_controller.rb:
    @isbn = params[:q]
    @search_type = params[:search_type]
... 
    @prices = Generalsearch.new(:search_term => @isbn, :search_type => @search_type)

generalsearch.rb

    attr_accessor :search_term , :search_type
    def initialize(search_term , search_type)
      self.search_term= search_term
      self.search_type= search_type
    end
...
Run Code Online (Sandbox Code Playgroud)

我一直在

wrong number of arguments (1 for 2)
app/models/generalsearch.rb:11:in `initialize'
app/controllers/book_controller.rb:47:in `new'
app/controllers/book_controller.rb:47:in `view' 
Run Code Online (Sandbox Code Playgroud)

Nar*_*iya 7

你只传递一个参数,即:search_term => @isbn, :search_type => @search_type在Generalsearch.new()中的哈希

使用

Generalsearch.new( @isbn, @search_type)
Run Code Online (Sandbox Code Playgroud)