简体   繁体   中英

Rails rendered but doesn't appear

Please excuse my english if it's not perfect.

I know there are already different topics about this type of problem but none has brought an effective solution in my case.

I have a sidebar and in logs, I can see it's rendered but it doesn't appear in the view or when I inspect the elements.

I don't see any error in the code but maybe you'll see something.

_sidebar.slim:

= content_for(:leftbar) do
  .leftbar-nav
    .leftbar-content
      .leftbar-block
        = render('shared/clients_ratings')
      .leftbar-block
        = render('themes/list')
      .leftbar-block
        = render('shared/social_share')
      .cta-block
        = widget_content('sidebar-list-public-orders')

Rendered in _orders.slim:

- unless identity_signed_in?
  = render 'shared/cta_blocks'

- if @orders.size > 0
    = render @orders
    = paginate @orders
- else
  p
    | There are no orders.

= render('themes/sidebar')

Rendered in index.slim:

- content_for(:full_width) do
  .neo-page-header
    .container
      .neo-page-header-title
        h1 Title

  .container
    = render('orders/orders')

Finally, I have a content_for?(:leftbar) in my application.slim:

doctype html
html lang="fr"
  = render "layouts/head"
  body class= "#{yield(:app_class)}"
    #wrap
      = render 'shared/flash_messages'
      = render 'shared/admin_navbar'
      - if identity_signed_in?
        = render 'shared/navbar'
      - else
        = render 'shared/navbar_guest'
      = render 'shared/banner' unless hide_banner? or identity_signed_in?

      = render('shared/confirmation_notice')

      - if content_for(:full_width)
        = yield(:full_width)

      - elsif content_for?(:sidebar)
        .container
          .row
            .col-lg-9.col-md-9
              = yield
            .col-lg-3.col-md-3
              = yield :sidebar

      - elsif content_for?(:leftbar)
        .container
          .row
            .col-lg-3.col-md-3
              = yield :leftbar
            .col-lg-9.col-md-9.main-content
              = yield
      - else
        .container
          = yield

In your application.slim you have - if content_for(:full_width) . This probably returns some truthy value so any other elsif won't be executed. I believe it should be - if content_for?(:full_width)

应该是= yield :leftbar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM