Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yield and default case || do not output default case

I have a simple yield use case and for some unknown reason the default case is never shown:

In my super_admin layout I have:

<%= yield :body_id || 'super_admin_main' %>

My controller

class Superadmin::GolfsController < ApplicationController
  layout "super_admin"

  def show 

  end
end

My show view

With or without

<% content_for(:body_id) do %>sadmin_golfs<% end %>

With: sadmin_golfs is shown.

without: empty string is shown instead of super_admin_main

Can anyone reproduce the same behavior ?

like image 628
coulix Avatar asked May 25 '10 18:05

coulix


1 Answers

Try <%= yield(:title).presence || 'My Default Title' %>

Object#presence is equivalent to object.present? ? object : nil (AS 3 rc docs), and essentially allows the traditional syntax with the titles.

like image 61
DirectXMan12 Avatar answered Nov 15 '22 13:11

DirectXMan12