ArgumentError: wrong number of arguments (1 for 2)

前端 未结 2 519
佛祖请我去吃肉
佛祖请我去吃肉 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:19

    update_column takes two arguments. You are only passing one.

    Instead of:

    @post.update_column(:ups => @post[:ups] + 1)
    

    Try:

    @post.update_column(:ups, @post[:ups] + 1)
    

    This may seem like two arguments:

    :ups => @post[:ups] + 1
    

    but it's actually one hash.

    With the more commonly used update_attributes, you can pass a hash:

    @post.update_attributes(:ups => @post[:ups] + 1)
    

提交回复
热议问题