[問題] count的使用
最近想要寫一個程式,
def create
@record = Record.new(params[:record])
if Record.count(:conditions => "seatnumber = @record.seatnumber") == 0
@record.punishment = "無"
elsif Record.count(:conditions => "seatnumber = @record.seatnumber") == 1
@record.punishment = "週末輔導"
else
@record.punishment = "警告乙支"
end
if @record.save
flash[:notice] = '紀錄新增成功!'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
但是在if Record.count(:conditions => "seatnumber = @record.seatnumber") == 0
這行中,@record.seatnumber沒辦法換成form上的資料,是不是有別種寫法才對?
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.166.2
推
10/12 22:54, , 1F
10/12 22:54, 1F
推
10/12 23:07, , 2F
10/12 23:07, 2F
推
10/12 23:26, , 3F
10/12 23:26, 3F
討論串 (同標題文章)
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章