是否有像这样的标准辅助方法:
def standard_save model
model_sym = model.class.name.underscore.to_sym
model.update_attributes params[model_sym]
if model.save
yield
redirect_to model
else
render :new
end
model
end
你会这样使用:
def create
standard_save(@user = User.new) {
flash[:success] = "You account was successfully created"
}
end
def update
standard_save @user = User.find(params[:id])
end