class EntriesController < ApplicationController before_action :set_entry, only: [:show] def index @supported_languages = SupportedLanguage.where(active: true).order(:sort_order, :name) @language_code = params[:language].presence @category = params[:category].presence @query = params[:q].to_s.strip @starts_with = params[:starts_with].presence entries_scope = Entry.all entries_scope = entries_scope.with_category(@category) entries_scope = entries_scope.search(@query, language_code: @language_code) entries_scope = entries_scope.starts_with(@starts_with, language_code: @language_code) if @starts_with.present? entries_scope = entries_scope.alphabetical_for(@language_code) if @query.blank? && @starts_with.blank? && @language_code.present? entries_scope = entries_scope.order(created_at: :desc) if entries_scope.order_values.empty? @entries = entries_scope.limit(50) @entry_count = Entry.count @verified_count = Entry.where(verified: true).count @recent_entries = Entry.order(created_at: :desc).limit(6) end def show @supported_languages = SupportedLanguage.where(active: true).order(:sort_order, :name) end def download @entries = Entry.order(:id) respond_to do |format| format.xlsx do filename = "sanasto-entries-#{Time.zone.today}.xlsx" response.headers["Content-Disposition"] = "attachment; filename=\"#{filename}\"" end end end private def set_entry @entry = Entry.find(params[:id]) end end