gobierto icon indicating copy to clipboard operation
gobierto copied to clipboard

ActionView::Template::Error happened in GobiertoCms::PagesController#show

Open appsignal[bot] opened this issue 3 years ago • 3 comments

Message

  undefined method `title' for GobiertoBudgets:Module

Backtrace (last 10 lines)

app/helpers/gobierto_cms/page_helper.rb:10 block in section_tree
lib/active_record/relation/delegation.rb:87 each
lib/active_record/relation/delegation.rb:87 each
app/helpers/gobierto_cms/page_helper.rb:9 section_tree
app/views/gobierto_cms/shared/_pages_side_navigation.html.erb:4
lib/action_view/base.rb:274 _run
lib/action_view/template.rb:185 block in render
lib/appsignal/hooks/active_support_notifications.rb:19 block in instrument
lib/active_support/notifications/instrumenter.rb:24 instrument
lib/appsignal/hooks/active_support_notifications.rb:18 instrument

View on AppSignal: https://appsignal.com/populate/sites/5ebb88520264445dc7e68b5c/exceptions/incidents/248?timestamp=2021-07-13T06:13:17Z

appsignal[bot] avatar Jul 13 '21 06:07 appsignal[bot]

Please, review if it's something related with the current refactor or it was an old bug, and please solve it.

ferblape avatar Jul 13 '21 06:07 ferblape

so the code involved is

https://github.com/PopulateTools/gobierto/blob/00939f4ea27e9016f60e85fcd8bb0e37c8e41c07/app/views/gobierto_cms/shared/_pages_side_navigation.html.erb#L1-L15

error message: undefined method title' for GobiertoBudgets:Module`

it looks like @collection which have collection_item, one of collection item is taking a value of type GobiertoBudgets:Module which don't have title.

this shared partial is used into index, let's see

   def index
      @page = find_page
      @collection = current_site.collections.find_by!(slug: params[:id])
       render_404 and return false if @collection.item_type != "GobiertoCms::Page"
    end

    def find_page
      page = pages_scope.find_by!(slug: params[:id])
      @collection = page.collection
      if @collection.nil? || (!page.public? && !valid_preview_token?)
        raise ActiveRecord::RecordNotFound
      end
      GobiertoCms::PageDecorator.new(page, @collection.container_type, @collection.item_type)
    end

   def pages_scope
      valid_preview_token? ? current_site.pages : current_site.pages.active
    end

It looks like the collection is protected so, let's see the view

 <% elsif @collection %>
         <ul>
            ... <%= link_to @collection.title, gobierto_cms_pages_path(@collection.slug) %>
               <ul>
                  <%= render partial: "gobierto_cms/shared/page", collection: @pages, cached: true %>
                   <!-- CHANGES at gobierto_cms/shared/page -->
                    <li><%= link_to page.title, gobierto_cms_page_or_news_path(page) %></li>
                    <!-- CHANGES at obierto_cms/shared/page -->
               </ul>
         </ul>
    </ul>
  <% end %>

I think that the problem can be into render partial, which is calling page.title so we can fix

                   <!-- CHANGES at gobierto_cms/shared/page -->
                    <% if page && (@collection.type == 'GobiertoCms::Page' %>
                    <li><%= link_to page.title, gobierto_cms_page_or_news_path(page) %></li>
                    <% end %>
                    <!-- CHANGES at obierto_cms/shared/page -->

I'm not really sure about, there are wrong collection item to Collection?

stbnrivas avatar Jul 13 '21 08:07 stbnrivas

my first approach was reproduce the bug using two sections:

  • https://santander.gobierto.test/s/cms/cms-section-l0-p0
  • https://santander.gobierto.test/s/other-section/other-page-for-other-section take page slug and interchange
  • https://santander.gobierto.test/s/cms/other-page-for-other-section
  • https://santander.gobierto.test/s/other-section/cms-section-l0-p0

but if visits this url already (without changes into the code) you will get an 404. Also add a PR for with a test for this and some minor typo.

But I was wrong...

stbnrivas avatar Jul 14 '21 07:07 stbnrivas