Ruby on Rails: is there a standard helper for minimalist implementation of create and update actions?

Is there any standard helper method in rails like this:

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

What will you use like this:

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
+3
source share
1 answer

There inherited_resources gem you can use for this.

+5
source

Source: https://habr.com/ru/post/1782131/


All Articles