我正在制作一个简单的 Rails 站点,它将存储一些日期并执行基本的条件检查。我在下面写了一些方法,并被告知我可以让它们更有效率。我一直在挠头,我不知道该怎么做。我应该让 entry.find 全球化吗?还是有更明显的解决方案?提前致谢
def name
@fname = params[:fst_name]
@lname = params[:lst_name]
@entry = Entry.create({:first_name => @fname, :last_name => @lname})
end
def attribs
@person = Entry.find(:last)
@fname = @person.first_name
@lname = @person.last_name
@person.update_attributes({:address => params[:st_name],
:salary => params[:salary], :loan => params[:loan],
:loan_reason => params[:reason]})
if !@person.address.nil? then render "show" end
end
def show
@person = Entry.find(:last)
end
def modify
@person = Entry.find(:last)
@fname = @person.first_name
@lname = @person.last_name
@entry = Entry.create({:first_name => @fname, :last_name => @lname,
:salary => params[:salary], :loan => params[:loan]})
end
def borrow
@person = Entry.find(:last)
if !@person.salary.nil? then
if (@person.salary * 3) < @person.loan
then @message = "You have asked for too much"
else @message = "No problem"
end
else @message = "empty record?"
end
end
end