因此,對於所有正在執行的意圖和目的,我都有相同的操作。然而,一件作品和另一件作品沒有。沒有將字符串隱式轉換爲數組
DB設置
add_column :cards, :score, :integer, :default => 0
add_column :cards, :comments, :integer, :default => 0
=> Card(id: integer, user_id: integer, event: text, created_at: datetime, updated_at: datetime, score: integer, comments: integer)
表決控制器(這一個工程)
def create
@vote = Vote.where(:card_id => params[:vote][:card_id], :user_id => current_user.id).first
if @vote
@vote.up = params[:vote][:up]
@vote.save
@card = Card.find(params[:vote][:card_id])
if @vote.up == true
@card.score += 2
else
@card.score -= 2
end
@card.save
else
@vote = Vote.new
@vote.card_id = params[:vote][:card_id]
@vote.user = current_user
@vote.up = params[:vote][:up]
@vote.save
@card = Card.find(params[:vote][:card_id])
if @vote.up == true
@card.score += 1
else
@card.score -= 1
end
@card.save
end
redirect_to :back
end
評論控制器(不工作),我得到 「Fixnum對象的隱式轉換爲陣」
def create
@comment = Comment.new
@comment.message = params[:comment][:message]
@comment.card_id = params[:comment][:card_id]
@comment.user = current_user
@comment.save
@card = Card.find(params[:comment][:card_id])
@card.comments += 1
@card.save
redirect_to :back
end
我在這裏錯過了什麼?謝謝大家提前的幫助。
伊恩