<commit_before>require_dependency "webinius_cms/application_controller"

module WebiniusCms
  class ListItemsController < ApplicationController
    layout 'webinius_cms/admin'

    before_action :set_list, only: [:index, :create, :new, :edit, :update, :destroy]
    before_action :set_list_item, only: [:show, :edit, :update, :destroy]

    # GET /list_items
    def index
      @list_items = @list.list_items
    end

    # GET /list_items/1
    def show
    end

    # GET /list_items/new
    def new
      @list_item = ListItem.new
      @list_item.documents.build
    end

    # GET /list_items/1/edit
    def edit
      @list_item.documents.build
    end

    # POST /list_items
    def create
      @list_item = ListItem.new(list_item_params)
      @list_item.list = @list

      if @list_item.save
        redirect_to list_list_items_url, notice: 'List item was successfully created.'
      else
        render :new
      end
    end

    # PATCH/PUT /list_items/1
    def update
      if @list_item.update(list_item_params)
        redirect_to list_list_items_url, notice: 'List item was successfully updated.'
      else
        render :edit
      end
    end

    # DELETE /list_items/1
    def destroy
      @list_item.destroy
      redirect_to list_list_items_url, notice: 'List item was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_list_item
        @list_item = ListItem.find(params[:id])
      end

      def set_list
        @list = List.find(params[:list_id])
      end

      # Only allow a trusted parameter "white list" through.
      def list_item_params
        langs = Language.all
        dynamic_fields = %w[title content meta_description slug description].collect do |field|
          lang_field = []
          langs.each do |lang|
            lang_field << "#{lang.code}_#{field}"
          end
          lang_field
        end.flatten!
        params.require(:list_item).permit(:status, :picture, *dynamic_fields, documents_attributes: [:id, :name, :document, :document_cache, :_destroy])
      end
  end
end<commit_msg>bug fix for images for list items<commit_after>require_dependency "webinius_cms/application_controller"

module WebiniusCms
  class ListItemsController < ApplicationController
    layout 'webinius_cms/admin'

    before_action :set_list, only: [:index, :create, :new, :edit, :update, :destroy]
    before_action :set_list_item, only: [:show, :edit, :update, :destroy]

    # GET /list_items
    def index
      @list_items = @list.list_items
    end

    # GET /list_items/1
    def show
    end

    # GET /list_items/new
    def new
      @list_item = ListItem.new
      @list_item.documents.build
    end

    # GET /list_items/1/edit
    def edit
      @list_item.documents.build
    end

    # POST /list_items
    def create
      @list_item = ListItem.new(list_item_params)
      @list_item.list = @list

      if @list_item.save
        redirect_to list_list_items_url, notice: 'List item was successfully created.'
      else
        render :new
      end
    end

    # PATCH/PUT /list_items/1
    def update
      if @list_item.update(list_item_params)
        redirect_to list_list_items_url, notice: 'List item was successfully updated.'
      else
        render :edit
      end
    end

    # DELETE /list_items/1
    def destroy
      @list_item.destroy
      redirect_to list_list_items_url, notice: 'List item was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_list_item
        @list_item = ListItem.find(params[:id])
      end

      def set_list
        @list = List.find(params[:list_id])
      end

      # Only allow a trusted parameter "white list" through.
      def list_item_params
        langs = Language.all
        dynamic_fields = %w[title content meta_description slug description].collect do |field|
          lang_field = []
          langs.each do |lang|
            lang_field << "#{lang.code}_#{field}"
          end
          lang_field
        end.flatten!
        params.require(:list_item).permit(:status, :remove_picture, :picture, :picture_cache, *dynamic_fields, documents_attributes: [:id, :name, :document, :document_cache, :_destroy])
      end
  end
end
{'fraction_non_alphanumeric': 0.08450704225352113, 'fraction_numerical': 0.0018471484645578389, 'mean_word_length': 2.5190901705930138, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5995759', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1310, 'n_words': 345}