mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	 caca99a823
			
		
	
	caca99a823
	
	
	
		
			
			* fix: resolves issue with non updating article view count Co-authored-by: BikashSah999 <51731962+BikashSah999@users.noreply.github.com> * Update articles_controller.rb --------- Co-authored-by: BikashSah999 <51731962+BikashSah999@users.noreply.github.com> Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| class Public::Api::V1::Portals::ArticlesController < PublicController
 | |
|   before_action :ensure_custom_domain_request, only: [:show, :index]
 | |
|   before_action :portal
 | |
|   before_action :set_category, except: [:index]
 | |
|   before_action :set_article, only: [:show]
 | |
|   layout 'portal'
 | |
| 
 | |
|   def index
 | |
|     @articles = @portal.articles
 | |
|     @articles = @articles.search(list_params) if list_params.present?
 | |
|   end
 | |
| 
 | |
|   def show; end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def set_article
 | |
|     @article = @category.articles.find(params[:id])
 | |
|     @article.views = @article.views ? @article.views + 1 : 1
 | |
|     @article.save
 | |
|     @parsed_content = render_article_content(@article.content)
 | |
|   end
 | |
| 
 | |
|   def set_category
 | |
|     @category = @portal.categories.find_by!(slug: params[:category_slug]) if params[:category_slug].present?
 | |
|   end
 | |
| 
 | |
|   def portal
 | |
|     @portal ||= Portal.find_by!(slug: params[:slug], archived: false)
 | |
|   end
 | |
| 
 | |
|   def list_params
 | |
|     params.permit(:query)
 | |
|   end
 | |
| 
 | |
|   def render_article_content(content)
 | |
|     # rubocop:disable Rails/OutputSafety
 | |
|     CommonMarker.render_html(content).html_safe
 | |
|     # rubocop:enable Rails/OutputSafety
 | |
|   end
 | |
| end
 |