作者dickcd (迪克)
看板Ruby
標題[問題] count的使用
時間Fri Oct 12 22:48:51 2007
最近想要寫一個程式,
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
1F:推 godfat:"seatnumber = #@record.seatnumber" 10/12 22:54
2F:推 shelary:"seatnumber = #{@record.seatnumber}" 10/12 23:07
3F:推 dickcd:謝謝! 10/12 23:26