Module: SimpleCrud

Defined in:
lib/simple_crud.rb,
lib/simple_crud/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#class_name(instance) ⇒ Object



3
4
5
# File 'lib/simple_crud.rb', line 3

def class_name(instance)
  instance.class.name.underscore.humanize
end

#create_(instance, path, r) ⇒ Object

Save the instance, Redirect_to if save successful, #render template if not successful



7
8
9
10
11
12
13
# File 'lib/simple_crud.rb', line 7

def create_(instance, path, r) # Save the instance, Redirect_to if save successful, #render template if not successful
  if instance.save
    redirect_to path, notice: class_name(instance) + " created."
  else
    render r
  end
end

#destroy_(instance, path) ⇒ Object

Delete instance, Redirect_to after delete



23
24
25
26
# File 'lib/simple_crud.rb', line 23

def destroy_(instance, path) # Delete instance, Redirect_to after delete
  instance.destroy
  redirect_to path, notice: class_name(instance) + " deleted."
end

#update_(instance, strong_params, path) ⇒ Object

Update the instance, Redirect_to if successful, # Always renders edit



15
16
17
18
19
20
21
# File 'lib/simple_crud.rb', line 15

def update_(instance, strong_params, path) # Update the instance, Redirect_to if successful, # Always renders edit
  if instance.update(strong_params)
    redirect_to path, notice: class_name(instance) + " updated."
  else
    render :edit
  end
end