lib/generators/breadko/templates/breadkos_controller.erb
class <%= objects.camelize %>Controller < ApplicationController
before_action :<%= object %>, except: [:index, :new, :create]
def index
@<%= objects %> = current_account.<%= objects %>
respond_to do |format|
format.html
<% if with_datatable? -%>
format.json do
render json: <%= object.camelize %>Datatable.new(view_context,
current_account: current_account)
end
<% end -%>
end
end
def new
@<%= object %> = current_account.<%= objects %>.new
end
def create
@<%= object %> = current_account.<%= objects %>.new <%= object %>_params
if @<%= object %>.save
redirect_to <%= objects %>_path
else
render 'new'
end
end
def edit; end
def update
if @<%= object %>.update(<%= object %>_params)
redirect_to <%= objects %>_path
else
render 'edit'
end
end
def show; end
def destroy
@<%= object %>.destroy
redirect_to <%= objects %>_path
end
private
def <%= object %>
@<%= object %> ||= current_account.<%= objects %>.find(params[:id])
end
def <%= object %>_params
params.require(:<%= object %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
end
end