Module: ArticlesHelper
- Defined in:
- app/helpers/articles_helper.rb
Instance Method Summary collapse
- #article_command_options(article) ⇒ Object
- #article_conversion_options(article) ⇒ Object
- #article_state_label(article) ⇒ Object
- #polymorphic_article_path(article) ⇒ Object
- #safe_edit_path(record) ⇒ Object
- #setup_training_article(article) ⇒ Object
- #time_choices_for_article ⇒ Object
Instance Method Details
#article_command_options(article) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/articles_helper.rb', line 7 def (article) links = [] links << link_to( "Edit", send('edit_' + params[:controller].singularize + '_path', article)) if can?(:update, article) links << link_to( "Convert to PDF", send(params[:controller].singularize + '_path', format: :pdf)) links << link_to( "Send by Email", send('send_by_email_' + params[:controller].singularize + '_path')) links << link_to( "Delete", send(params[:controller].singularize + '_path'), data: { turbo_confirm: "Are you sure?", turbo_method: :delete } ) if can?(:destroy, article) links end |
#article_conversion_options(article) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/articles_helper.rb', line 17 def (article) conversions = { 'ArticleFaq' => 'Faq', 'ArticleTechnical' => 'Technical', 'ArticleTraining' => 'Training', 'ArticleProcedure' => 'Procedure' } links = [] conversions.each do |sti_type, label| next if article.type == sti_type links << link_to("Convert to #{label}", send("convert_type_#{params[:controller].singularize}_path", id: article, article_type_id: sti_type), data: { turbo_confirm: 'Are you sure you want to convert this article?' }) end links end |
#article_state_label(article) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/articles_helper.rb', line 43 def article_state_label(article) css_state = { draft: 'secondary', scheduled: 'info', published: 'success', archived: 'warn' }[article.state.to_sym] || 'default' content_tag(:span, article.human_state_name, class: "badge bg-#{css_state}") end |
#polymorphic_article_path(article) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/helpers/articles_helper.rb', line 35 def polymorphic_article_path(article) return nil unless article.present? && article.respond_to?(:to_model) polymorphic_path(article) rescue ActionController::UrlGenerationError, NoMethodError nil end |
#safe_edit_path(record) ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/helpers/articles_helper.rb', line 27 def safe_edit_path(record) return nil unless record.present? && record.respond_to?(:to_model) polymorphic_path([:edit, record]) rescue ActionController::UrlGenerationError, NoMethodError nil end |
#setup_training_article(article) ⇒ Object
53 54 55 56 57 58 |
# File 'app/helpers/articles_helper.rb', line 53 def setup_training_article(article) # Create one page of content article.tap do |article| article.article_pages.build(position: 1) unless article.article_pages.present? end end |
#time_choices_for_article ⇒ Object
3 4 5 |
# File 'app/helpers/articles_helper.rb', line 3 def time_choices_for_article [['',nil]] + (15..240).step(15).to_a.map{ |t| ["#{t} min", t] } end |