Class: Sipity::Controllers::CitationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sipity/controllers/citations_controller.rb

Overview

Responsible for working on the citation of the given sip.

Instance Method Summary collapse

Methods inherited from ApplicationController

#message_for, #repository

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/sipity/controllers/citations_controller.rb', line 33

def create
  run(sip_id: sip_id, attributes: create_attributes) do |on|
    on.success do |sip|
      redirect_to(sip_path(sip.to_param), notice: message_for(:success, title: sip.title))
    end
    on.failure do |form|
      @model = form
      respond_with(@model)
    end
  end
end

#create_attributesObject (private)



55
56
57
# File 'app/controllers/sipity/controllers/citations_controller.rb', line 55

def create_attributes
  params.require(:citation)
end

#newObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/sipity/controllers/citations_controller.rb', line 21

def new
  run(sip_id: sip_id) do |on|
    on.citation_not_assigned do |sip|
      @model = sip
      respond_with(@model)
    end
    on.citation_assigned do |sip|
      redirect_to(sip_citation_path(sip.to_param), notice: message_for(:citation_assigned, title: sip.title))
    end
  end
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/sipity/controllers/citations_controller.rb', line 9

def show
  run(sip_id: sip_id) do |on|
    on.citation_not_assigned do |sip|
      redirect_to(new_sip_citation_path(sip.to_param), alert: message_for(:citation_not_assigned, title: sip.title))
    end
    on.citation_assigned do |sip|
      @model = sip
      respond_with(@model)
    end
  end
end

#sip_idObject (private)



51
52
53
# File 'app/controllers/sipity/controllers/citations_controller.rb', line 51

def sip_id
  params.require(:sip_id)
end