Module: LazyCrud

Extended by:
ActiveSupport::Concern
Defined in:
lib/lazy_crud.rb,
lib/lazy_crud/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.9.2"

Instance Method Summary collapse

Instance Method Details

#createObject


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lazy_crud.rb', line 56

def create
  @resource = resource_proxy.build(resource_params)

  # ensure we can still use model name-based instance variables
  set_resource_instance

  if @resource.save
    flash[:notice] = "#{resource_name} has been created."
    redirect_to action: :index
  else
    render action: :new
  end
end

#destroyObject


78
79
80
81
82
83
# File 'lib/lazy_crud.rb', line 78

def destroy
  @resource.destroy

  flash[:notice] = "#{resource_name} has been deleted."
  redirect_to action: :index
end

#editObject


52
53
54
# File 'lib/lazy_crud.rb', line 52

def edit
  # instance variable set in before_action
end

#indexObject


40
41
42
# File 'lib/lazy_crud.rb', line 40

def index
  set_collection_instance
end

#newObject


48
49
50
# File 'lib/lazy_crud.rb', line 48

def new
  set_resource_instance(resource_proxy.new)
end

#showObject


44
45
46
# File 'lib/lazy_crud.rb', line 44

def show
  # instance variable set in before_action
end

#undestroyObject

only works if deleting of resources occurs by setting the deleted_at field


87
88
89
90
91
92
93
94
95
96
# File 'lib/lazy_crud.rb', line 87

def undestroy
  @resource = resource_proxy(true).find(params[:id])
  set_resource_instance

  @resource.deleted_at = nil
  @resource.save

  flash[:notice] = "#{resource_name} has been undeleted"
  redirect_to action: :index
end

#updateObject


70
71
72
73
74
75
76
# File 'lib/lazy_crud.rb', line 70

def update
  if @resource.update(resource_params)
    redirect_to action: :index
  else
    redirect_to action: :edit
  end
end