Ruby on Rails:是否有一个标准帮助程序,用于简化实现创建和更新操作?

时间:2010-12-26 00:08:14

标签: ruby-on-rails controller action

是否有像这样的标准辅助方法:

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

1 个答案:

答案 0 :(得分:5)

你可以使用inherited_resources宝石。