我无法找出这个极其简单的错误:

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
...

我一直在
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'

最佳答案

在Generalsearch.new()中只传递一个参数ie hash:search_term => @isbn, :search_type => @search_type
使用

Generalsearch.new( @isbn, @search_type)

10-04 21:38