Class: CreatorsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CreatorsController
- Includes:
- LinkableController, ModelListable, Permittable
- Defined in:
- app/controllers/creators_controller.rb
Instance Method Summary collapse
- #avatar ⇒ Object
- #banner ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from LinkableController
Methods included from Permittable
Instance Method Details
#avatar ⇒ Object
120 121 122 123 |
# File 'app/controllers/creators_controller.rb', line 120 def avatar @creator send_file_content @creator.avatar, disposition: :inline end |
#banner ⇒ Object
125 126 127 128 |
# File 'app/controllers/creators_controller.rb', line 125 def @creator send_file_content @creator., disposition: :inline end |
#create ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/creators_controller.rb', line 64 def create Creator @creator = Creator.create(creator_params.merge(owner: current_user)) respond_to do |format| format.html do if @creator.valid? if flash[:return_after_new] redirect_to flash[:return_after_new] + "?new_creator=#{@creator.to_param}", notice: t(".success") else redirect_to creator_path(@creator), notice: t(".success") end else render :new, status: :unprocessable_content end end format.manyfold_api_v0 do if @creator.valid? render json: ManyfoldApi::V0::CreatorSerializer.new(@creator).serialize, status: :created, location: creator_path(@creator) else render json: @creator.errors.to_json, status: :unprocessable_content end end end end |
#destroy ⇒ Object
112 113 114 115 116 117 118 |
# File 'app/controllers/creators_controller.rb', line 112 def destroy @creator.destroy respond_to do |format| format.html { redirect_to creators_path, notice: t(".success") } format.manyfold_api_v0 { head :no_content } end end |
#edit ⇒ Object
61 62 |
# File 'app/controllers/creators_controller.rb', line 61 def edit end |
#index ⇒ Object
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 |
# File 'app/controllers/creators_controller.rb', line 9 def index @creators = policy_scope(Creator) @models = policy_scope(Model).all if @filter.any? @models = @filter.models(@models) @creators = @filter.creators(@creators, @models) end @tags, @unrelated_tag_count = generate_tag_list(@models, @filter.) @tags, @kv_tags = (@tags) @unrelated_tag_count = nil unless @filter.any? # Ordering @creators = apply_sort_order(@creators) page = params[:page] || 1 @creators = @creators.page(page).per(helpers.pagination_settings["per_page"]) # Eager load data @creators = @creators.includes(:links, :collections) # Apply tag filters in-place @filter_in_place = true # Count unassiged models @unassigned_count = policy_scope(Model).where(creator: nil).count set_indexable @creators respond_to do |format| format.html { render layout: "card_list_page" } format.manyfold_api_v0 { render json: ManyfoldApi::V0::CreatorListSerializer.new(@creators).serialize } end end |
#new ⇒ Object
54 55 56 57 58 59 |
# File 'app/controllers/creators_controller.rb', line 54 def new Creator @creator = Creator.new @title = t("creators.general.new") flash.keep(:return_after_new) end |
#show ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/creators_controller.rb', line 41 def show respond_to do |format| format.html do @models = policy_scope(Model).where(creator: @creator) prepare_model_list @additional_filters = {creator: @creator} render layout: "card_list_page" end format. { render json: OEmbed::CreatorSerializer.new(@creator, helpers.).serialize } format.manyfold_api_v0 { render json: ManyfoldApi::V0::CreatorSerializer.new(@creator).serialize } end end |
#update ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/creators_controller.rb', line 89 def update @creator.update(creator_params) respond_to do |format| format.html do if @creator.valid? redirect_to @creator, notice: t(".success") else # Restore previous slug @attemped_slug = @creator.slug @creator.slug = @creator.slug_was render :edit, status: :unprocessable_content end end format.manyfold_api_v0 do if @creator.valid? render json: ManyfoldApi::V0::CreatorSerializer.new(@creator).serialize else render json: @creator.errors.to_json, status: :unprocessable_content end end end end |