我正在通过StackSkills通过一个类来工作,它们的问题链接已经消失。我不断收到“错误的参数数量(给定1,预期为0)”
我正在设置一个商业程序。到目前为止,我已经设置了数据库来存储发票信息(日期,税率,销售人员,公司名称)。我按照说明在发票清单中创建了一个搜索字段,可以让我按日期范围进行搜索。当我尝试加载发票清单,我得到一个错误说:
ArgumentError in InvoicesController#index
wrong number of arguments (given 1, expected 0)
Extracted source (around line #7):
5 # GET /invoices.json
6 def index
7 @search = InvoiceSearch.new(params[:search])
8 @invoices = @search.scope
9 end
这是被添加到我的InvoicesController.rb文件本练习代码:
def index
@search = InvoiceSearch.new(params[:search])
@invoices = @search.scope
end
这是invoice_Search .RB这是在这个课程中创建:
class InvoiceSearch
attr_reader :date_from, :date_to
def initializ(params)
params ||={}
@date_from = parsed_date(params[:date_from], 7.days.ago.to_date.to_s)
@date_to = parsed_date(params[:date_to], Date.today.to_s)
end
def scope
Invoice.where('date BETWEEN ? AND ?', @date_from, @date_to)
end
private
def parsed_date(date_string, default)
Date.parse(date_string)
rescue ArgumentError, TypeError
default
end
end
而这正是被添加到我的index.html.erb文件这一课(列出在数据库中的发票页):
<div class="row">
<h1>Listing Invoices</h1>
<div class="pull-right range-query">
<%= form_tag invoices_path, method: :get do %>
<%= text_field_tag 'search[date_from]', @search.date_from %>
<%= text_field_tag 'search[date_to]', @search.date_to %>
<%= submit_tag 'Search', class: 'btn search-button' %>
<% end %>
</div>
</div>
什么是你的问题?确切地说是 – sawa