Nifty Generators LayoutHelper Issue

On my first Rails project, I used Ryan Bates' Nifty Generators to generate application source files. This gives me LayoutHelper

with the titration method:

def title(page_title, show_title = true)
  @content_for_title = page_title.to_s
  @show_title = show_title
end

      

In my home view, I have a simple header:

<%= title "Welcome" -%>

      

And finally, in my layout ( application.html.erb

), I have:

<%- if show_title? -%>
  <h1><%=h yield(:title) %></h1>
<%- end -%>

<%= yield %>

      

What I see is my heading "Welcome" followed by the past (or default) value for show_title

. I need the first, but not the last. I understand why the boolean value is implicitly returned by the method, but I was not expecting it to be displayed. The logical mapping seems to be displayed as part of the main content yield

.

The command yield

still hasn't clicked on me yet (I understand, I just don't understand it if that makes sense), so I hope someone can help me understand why the boolean is being printed and how I can get it to stop. This answer may help me understand better how it yield

works in addition to solving the immediate problem.

Thank.

+2


source to share


1 answer


Try the following:

<% title "Welcome" %>

      



You want to call a method title

, not call its return value when you call it.

+3


source







All Articles