作者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