Module: Controllers::Articlable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ArticleFaqsController, ArticleProceduresController, ArticleTechnicalsController, ArticleTrainingsController, Crm::PostCommentsController, Crm::PostsController
- Defined in:
- app/concerns/controllers/articlable.rb
Instance Method Summary collapse
- #convert_type ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #load_article ⇒ Object protected
- #show ⇒ Object
- #show_description ⇒ Object
- #show_solution ⇒ Object
Instance Method Details
#convert_type ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/concerns/controllers/articlable.rb', line 53 def convert_type load_article new_type = params[:article_type_id].to_s unless Article::STI_TYPES.key?(new_type) flash[:error] = 'Invalid article type for conversion.' redirect_to polymorphic_path(@article) and return end @article.update_columns(type: new_type, state: 'draft') converted = Article.find(@article.id) flash[:info] = 'Article has been converted and changed to Draft state.' redirect_to polymorphic_path([:edit, converted]) rescue ActionController::UrlGenerationError, NoMethodError flash[:error] = 'Article converted but could not resolve edit path.' redirect_to articles_path end |
#destroy ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/concerns/controllers/articlable.rb', line 44 def destroy controller = controller_name load_article @article.destroy respond_to do |format| format.html { redirect_to_return_path_or_default send("#{controller}_path") } end end |
#edit ⇒ Object
39 40 41 42 |
# File 'app/concerns/controllers/articlable.rb', line 39 def edit load_article (:update, @article) end |
#index ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/concerns/controllers/articlable.rb', line 6 def index (:read, Article) klass = model_class @q = klass.ransack(params[:q]) @q.sorts = 'created_at DESC' if @q.sorts.blank? @pagy, @articles = pagy(@q.result.includes(:product_lines, taggings: :tag).order(created_at: :desc)) end |
#load_article ⇒ Object (protected)
73 74 75 |
# File 'app/concerns/controllers/articlable.rb', line 73 def load_article @article = model_class.friendly.find(params[:id]) end |
#show ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/concerns/controllers/articlable.rb', line 14 def show load_article respond_to do |format| format.html format.pdf do result = Pdf::Document::Article.call(@article) send_data result.pdf, filename: result.file_name, type: 'application/pdf', disposition: 'inline' rescue Pdf::Document::Article::GenerationError => e Rails.logger.error("[Articlable#show] PDF generation failed for article #{@article.id}: #{e.}") flash[:error] = 'PDF generation is temporarily unavailable. Please try again later.' redirect_to polymorphic_path(@article) end end end |
#show_description ⇒ Object
29 30 31 32 |
# File 'app/concerns/controllers/articlable.rb', line 29 def show_description load_article render layout: 'www/cms_page' end |
#show_solution ⇒ Object
34 35 36 37 |
# File 'app/concerns/controllers/articlable.rb', line 34 def show_solution load_article render layout: 'www/cms_page' end |