[英]ArgumentError - Wrong number of arguments when calling .all
I am very new to RoR and although I have done quite an extensive amount of searching on StackOverflow and Google, I can't seem to solve this problem. 我对RoR很新,虽然我在StackOverflow和Google上做了大量的搜索,但我似乎无法解决这个问题。
In my controller, I have the following code to initialize the @coupon_categories instance variable, and continuously get this error in my index method: 在我的控制器中,我有以下代码来初始化@coupon_categories实例变量,并在我的索引方法中不断得到此错误:
wrong number of arguments (0 for 1)
This is my CouponCategoryController file: 这是我的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
coupon_category.rb: coupon_category.rb:
class CouponCategory < ActiveRecord::Base
has_many :coupons, :dependent => destroy # destroys coupons dependent on coupon_category
end
Any insight would be greatly appreciated! 任何见解将不胜感激! Thank you :) 谢谢 :)
Edit: Here is my view file, along with the full error messages. 编辑:这是我的视图文件,以及完整的错误消息。 index.html.erb: 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' %>
Full error message: 完整的错误消息:
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'
Thank you for your help! 谢谢您的帮助!
The problem may be 问题可能是
has_many :coupons, :dependent => destroy
The destroy
should be a symbol, :destroy
. destroy
应该是一个象征, :destroy
。
has_many :coupons, :dependent => :destroy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.