Module: Api::ExternalLinks
- Extended by:
- ActiveSupport::Concern
- Included in:
- ChallengesController, ProgramsController, ProjectsController, SpacesController, UsersController, WorkgroupsController
- Defined in:
- app/controllers/concerns/api/external_links.rb
Instance Method Summary collapse
-
#create_link ⇒ Object
the params for this controller look like this: params.
- #destroy_link ⇒ Object
- #index_link ⇒ Object
- #update_link ⇒ Object
Instance Method Details
#create_link ⇒ Object
the params for this controller look like this: params
{ link_id: 32, link: { url: "Slack", icon: File } }
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/concerns/api/external_links.rb', line 24 def create_link link = ExternalLink.new(link_params) if params[:icon].present? link.icon.attach(params[:icon]) render(json: { error: 'Something went wrong with the icon (Probably not an image!)' }, status: :unprocessable_entity) && return unless link.icon.attached? && link.icon.variable? end if link.save! @obj.external_links << link render json: link, serializer: Api::ExternalLinkSerializer, status: :created else render json: { error: 'Something went wrong' }, status: :unprocessable_entity end end |
#destroy_link ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/controllers/concerns/api/external_links.rb', line 57 def destroy_link @obj.external_links.delete(@link) if @link.destroy render json: { data: 'Link destroyed' }, status: :ok else render json: { error: 'Something went wrong with the deletion' }, status: :unprocessable_entity end end |
#index_link ⇒ Object
39 40 41 |
# File 'app/controllers/concerns/api/external_links.rb', line 39 def index_link render json: @obj.external_links, each_serializer: Api::ExternalLinkSerializer, status: :ok end |
#update_link ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/concerns/api/external_links.rb', line 43 def update_link if params[:icon].present? @link.icon.purge @link.icon.attach(params[:icon]) render(json: { error: 'Something went wrong with the icon (Probably not an image!)' }, status: :unprocessable_entity) && return unless @link.icon.attached? && @link.icon.variable? end if @link.update(link_params) render json: @link, serializer: Api::ExternalLinkSerializer, status: :ok else render json: { error: 'Something went wrong with the update' }, status: :unprocessable_entity end end |