Class: Orcid::ProfileRequestsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/orcid/profile_requests_controller.rb

Overview

Responsible for helping a user request a new Orcid Profile.

chatty method names. The method names are fine, but the knowledge of Orcid::ProfileStatus is encapsulated in that class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

#path_for

Instance Attribute Details

#profile_requestObject (readonly)

Returns the value of attribute profile_request.



11
12
13
# File 'app/controllers/orcid/profile_requests_controller.rb', line 11

def profile_request
  @profile_request
end

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/orcid/profile_requests_controller.rb', line 27

def create
  return false if redirecting_because_user_has_connected_orcid_profile
  return false if redirecting_because_user_has_existing_profile_request
  assign_attributes(new_profile_request)
  create_profile_request(new_profile_request)
  # As a named singular resource, url_for(profile_request) treates the
  # input profile_request as the :format paramter. When you run
  # `$ rake app:routes` in this gem, there is not a named route for:
  # GET  /profile_request(.:format)         orcid/profile_requests#show
  #
  # Thus we need to pass the location.
  if new_profile_request.valid?
    flash[:notice] = I18n.t(
      'orcid.requests.messages.profile_request_created'
    )

    location = path_for(:after_successful_orcid_profile_request_path) do
      orcid.profile_request_path
    end

    respond_with(orcid, location: location)
  else
    respond_with(orcid, new_profile_request)
  end
end

#destroyObject



53
54
55
56
57
58
59
60
# File 'app/controllers/orcid/profile_requests_controller.rb', line 53

def destroy
  existing_profile_request.destroy if existing_profile_request
  flash[:notice] = I18n.t('orcid.requests.messages.profile_request_destroyed')
  location = path_for(:after_orcid_profile_request_destroyed_path) do
    orcid.new_profile_request_path
  end
  respond_with(orcid, location: location)
end

#newObject



20
21
22
23
24
25
# File 'app/controllers/orcid/profile_requests_controller.rb', line 20

def new
  return false if redirecting_because_user_has_connected_orcid_profile
  return false if redirecting_because_user_has_existing_profile_request
  assign_attributes(new_profile_request)
  respond_with(orcid, new_profile_request)
end

#showObject



14
15
16
17
18
# File 'app/controllers/orcid/profile_requests_controller.rb', line 14

def show
  return false if redirecting_because_user_has_connected_orcid_profile
  return false if redirecting_because_no_profile_request_was_found
  respond_with(orcid, existing_profile_request)
end