-
Notifications
You must be signed in to change notification settings - Fork 845
Expand file tree
/
Copy pathexternal_works_controller.rb
More file actions
74 lines (64 loc) · 1.9 KB
/
Copy pathexternal_works_controller.rb
File metadata and controls
74 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class ExternalWorksController < ApplicationController
before_action :admin_only, only: [:edit, :update]
before_action :users_only, only: [:new]
before_action :check_user_status, only: [:new]
def new
@page_subtitle = t(".page_title")
@bookmarkable = ExternalWork.new
@bookmark = Bookmark.new
end
# Used with bookmark form to get an existing external work and return it via ajax
def fetch
if params[:external_work_url]
url = begin
Addressable::URI.heuristic_parse(params[:external_work_url]).to_str
rescue Addressable::URI::InvalidURIError
nil
end
@external_work = ExternalWork.where(url: url).first if url
end
respond_to do |format|
format.js
end
end
def index
if params[:show] == "duplicates"
unless logged_in_as_admin?
access_denied
return
end
@external_works = ExternalWork.duplicate.order("created_at DESC").paginate(page: params[:page])
else
@external_works = ExternalWork.order("created_at DESC").paginate(page: params[:page])
end
end
def show
@external_work = ExternalWork.find(params[:id])
end
def edit
@external_work = authorize ExternalWork.find(params[:id])
@work = @external_work
end
def update
@external_work = authorize ExternalWork.find(params[:id])
@external_work.attributes = work_params
if @external_work.update(external_work_params)
flash[:notice] = t(".successfully_updated")
redirect_to(@external_work)
else
render action: "edit"
end
end
private
def external_work_params
params.require(:external_work).permit(
:url, :author, :title, :summary, :language_id
)
end
def work_params
params.require(:work).permit(
:rating_string, :fandom_string, :relationship_string, :character_string,
:freeform_string, category_strings: [], archive_warning_strings: []
)
end
end