Module: LazyCrud::InstanceMethods
- Included in:
- LazyCrud
- Defined in:
- lib/lazy_crud/instance_methods.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
-
#undestroy ⇒ Object
only works if deleting of resources occurs by setting the deleted_at field.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lazy_crud/instance_methods.rb', line 22 def create @resource = resource_proxy.send(build_method, resource_params) # ensure we can still use model name-based instance variables # such as @discount, or @event set_resource_instance run_before_create_hooks flash[:notice] = "#{resource_name} has been created." if @resource.save respond_with(@resource, location: { action: :index }) # if @resource.save # flash[:notice] = "#{resource_name} has been created." # redirect_to action: :index # else # render action: :new # end end |
#destroy ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/lazy_crud/instance_methods.rb', line 53 def destroy run_before_destroy_hooks @resource.destroy respond_with(@resource, location: { action: :index }) # flash[:notice] = "#{resource_name} has been deleted." # redirect_to action: :index end |
#edit ⇒ Object
18 19 20 |
# File 'lib/lazy_crud/instance_methods.rb', line 18 def edit # instance variable set in before_action end |
#index ⇒ Object
4 5 6 |
# File 'lib/lazy_crud/instance_methods.rb', line 4 def index respond_with(set_collection_instance) end |
#new ⇒ Object
13 14 15 16 |
# File 'lib/lazy_crud/instance_methods.rb', line 13 def new set_resource_instance(resource_proxy.new) respond_with(get_resource_instance) end |
#show ⇒ Object
8 9 10 11 |
# File 'lib/lazy_crud/instance_methods.rb', line 8 def show # instance variable set in before_action respond_with(get_resource_instance) end |
#undestroy ⇒ Object
only works if deleting of resources occurs by setting the deleted_at field
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lazy_crud/instance_methods.rb', line 64 def undestroy @resource = resource_proxy(true).find(params[:id]) set_resource_instance @resource.deleted_at = nil @resource.save respond_with(@resource, location: { action: :index }) # flash[:notice] = "#{resource_name} has been undeleted" # redirect_to action: :index end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lazy_crud/instance_methods.rb', line 41 def update run_before_update_hooks @resource.update(resource_params) respond_with(@resource, location: { action: :index }) # if @resource.update(resource_params) # redirect_to action: :index # else # redirect_to action: :edit # end end |