Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ArgumentError-调用时参数数目错误。全部_Ruby On Rails - Fatal编程技术网

Ruby on rails ArgumentError-调用时参数数目错误。全部

Ruby on rails ArgumentError-调用时参数数目错误。全部,ruby-on-rails,Ruby On Rails,我对RoR非常陌生,虽然我在StackOverflow和Google上做了大量搜索,但我似乎无法解决这个问题 在我的控制器中,我有以下代码来初始化@优惠券\类别实例变量,并在我的索引方法中不断得到此错误: wrong number of arguments (0 for 1) 这是我的CouponCategoryController文件: class CouponCategoryController < ApplicationController # Implemented wh

我对RoR非常陌生,虽然我在StackOverflow和Google上做了大量搜索,但我似乎无法解决这个问题

在我的控制器中,我有以下代码来初始化@优惠券\类别实例变量,并在我的索引方法中不断得到此错误:

wrong number of arguments (0 for 1)
这是我的CouponCategoryController文件:

class CouponCategoryController < ApplicationController

   # Implemented when user input taken
   def index
     @coupon_categories = CouponCategory.all
   end

   def new
     @coupon_category = CouponCategory.new(params[:coupon_category])
   end
class CouponCategoryController
优惠券_category.rb:

class CouponCategory < ActiveRecord::Base

  has_many :coupons, :dependent => destroy # destroys coupons dependent on coupon_category  

end
class CouponCategorydestroy#根据优惠券类别销毁优惠券
结束
如有任何见解,将不胜感激!谢谢:)

编辑:这是我的视图文件,以及完整的错误消息。 index.html.erb:

<h1> Create A Coupon Category! </h1>

<%= form_for :coupon_category do |f| %>
 Category Name: <%= f.text_field "name" %><br />
 Category expiration date (YYYY-MM-DD): <%= f.text_field "date_expired" %><br />
     <%= f.submit %>
<% end %>

<%= render :partial => 'coupon/index' %>
创建优惠券类别!
类别名称:
类别到期日期(YYYY-MM-DD):
'优惠券/索引'%>
完整错误消息:

ArgumentError in CouponCategoryController#index

wrong number of arguments (0 for 1)

app/models/coupon_category.rb:2:in `<class:CouponCategory>'
app/models/coupon_category.rb:1:in `<top (required)>'
app/controllers/coupon_category_controller.rb:5:in `index'
CouponCategoryController索引中的
ArgumentError
参数数目错误(0表示1)
app/models/优惠券\类别。rb:2:in`'
app/models/优惠券\类别。rb:1:in`'
应用程序/控制器/优惠券\类别\控制器。rb:5:在“索引”中
谢谢你的帮助

问题可能是

has_many :coupons, :dependent => destroy
destroy
应该是一个符号,
:destroy

has_many :coupons, :dependent => :destroy

你能发布你的完整的stacktrace吗?(在
错误的参数数下的所有内容
错误,包括行号)正如dylan所暗示的,问题几乎肯定不在您的索引方法中-代码看起来很好。很可能是视图中的某个内容,您没有向我们显示。感谢您的帮助-我已经更新了原始帖子,包括视图文件和应用程序错误跟踪。就是这样!非常感谢你的帮助!