Module: CRUDMixin
- Included in:
- Rango::RESTController
- Defined in:
- lib/rango/mixins/crud.rb
Instance Method Summary collapse
- #create(notice = "Created successfully", error = "Can't create", &block) ⇒ Object
- #edit(&block) ⇒ Object
- #index(&block) ⇒ Object
- #new(&block) ⇒ Object
- #show(&block) ⇒ Object
- #update(notice = "Updated successfully", error = "Can't update", &block) ⇒ Object
Instance Method Details
#create(notice = "Created successfully", error = "Can't create", &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rango/mixins/crud.rb', line 28 def create(notice = "Created successfully", error = "Can't create", &block) raise ArgumentError, "You have to provide a block" if block.nil? object = block.call if object.save [:notice] = notice redirect url(named_route, object) else [:error] = error render_relative "show" end end |
#edit(&block) ⇒ Object
22 23 24 25 26 |
# File 'lib/rango/mixins/crud.rb', line 22 def edit(&block) raise ArgumentError, "You have to provide a block" if block.nil? set_context_value(collection_name, block.call) autorender end |
#index(&block) ⇒ Object
4 5 6 7 8 |
# File 'lib/rango/mixins/crud.rb', line 4 def index(&block) raise ArgumentError, "You have to provide a block" if block.nil? set_context_value(collection_name, block.call) autorender end |
#new(&block) ⇒ Object
16 17 18 19 20 |
# File 'lib/rango/mixins/crud.rb', line 16 def new(&block) raise ArgumentError, "You have to provide a block" if block.nil? set_context_value(collection_name, block.call) autorender end |
#show(&block) ⇒ Object
10 11 12 13 14 |
# File 'lib/rango/mixins/crud.rb', line 10 def show(&block) raise ArgumentError, "You have to provide a block" if block.nil? set_context_value(collection_name, block.call) autorender end |
#update(notice = "Updated successfully", error = "Can't update", &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rango/mixins/crud.rb', line 40 def update(notice = "Updated successfully", error = "Can't update", &block) raise ArgumentError, "You have to provide a block" if block.nil? object = block.call if object.save [:notice] = notice redirect url(named_route, object) else [:error] = error render_relative "show" end end |