Module: CRUDMixin

Included in:
Rango::RESTController
Defined in:
lib/rango/mixins/crud.rb

Instance Method Summary collapse

Instance Method Details

#create(notice = "Created successfully", error = "Can't create", &block) ⇒ Object

Raises:

  • (ArgumentError)


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
    message[:notice] = notice
    redirect url(named_route, object)
  else
    message[:error] = error
    render_relative "show"
  end
end

#edit(&block) ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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
    message[:notice] = notice
    redirect url(named_route, object)
  else
    message[:error] = error
    render_relative "show"
  end
end