0
如果我有以下編輯方法:在更新方法在Rails中使用的編輯方法
def edit
@pet = Pet.find(params[:id])
end
及以下更新方法:
def update
@pet = Pet.find(params[:id])
if @pet.update_attributes(pet_params)
redirect_to(:action => 'show', :id => @pet.id)
else
render('index')
end
end
我能簡單地使用編輯方法在更新方法如:
def update
edit
if @pet.update_attributes(pet_params)
redirect_to(:action => 'show', :id => @pet.id)
else
render('index')
end
end