11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/darjeelink/api_controller.rb', line 11
def create
short_link = Darjeelink::ShortLink.create!(short_link_params)
render(
json: { short_link: "#{Darjeelink.domain}/#{short_link.shortened_path}" },
status: :created
)
rescue ActiveRecord::RecordNotUnique
render(
json: { error: "#{short_link_params[:shortened_path]} already used! Choose a different custom path" },
status: :bad_request
)
rescue ActiveRecord::RecordInvalid => e
render(
json: { error: e.message.to_s },
status: :bad_request
)
rescue ActionController::ParameterMissing
render(
json: { error: 'Missing required params' },
status: :bad_request
)
end
|