ArgumentError: wrong number of arguments (1 for 2)

前端 未结 2 496
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 23:47

I\'m very new to Rails, MVC, and CRUD, and I\'m trying to use the update method to change the amount of votes on a post. I have the following code in my Posts Controller upd

2条回答
  •  心在旅途
    2021-01-12 00:27

    As Mischa pointed out, update_column takes two arguments. However, I would discourage you from using this method. First, it skips validations which may not be what you want. Second, Rails has built-in methods for incrementing or decrementing values. In your case, you could change your controller method to something like this:

    if params[:vote] == 'up'
      @post.increment(:ups)
    elsif params[:vote] == 'down'
      @post.increment(:downs)
    end
    

提交回复
热议问题