content_for

13 views
Skip to first unread message

Michael McLaughlin

unread,
Mar 26, 2014, 10:47:48 PM3/26/14
to serve...@googlegroups.com
Hey, just wanted to ask really quick as i was pouring over the code you had written for the site and such:

I came across a content_for method you were using in the index.html.erb file in the website docs. I have not come across this in ruby yet probably because I have not had to use it yet. Is it only available in rails? I'm wondering why it's not working for me, and I'm thinking it's because i'm not using rails. Is there some way to work around this for a new ruby dev like myself? I've included relevant code below. It's not failing, but it's also not doing anything... which is no good either. Any help is greatly appreciated. :)


In my layout.html.erb

<% yield :jumbotron %><!-- custom jumbotron innards inside of page -->


In my view.html.erb

<!-- custom jumbotron innards -->
<% content_for :jumbotron do %>
  <div class="title-positionizer">
    <h4 class="heading no-breath text-center-xxs text-white">Logged in as <span class="heading-client-name">Name Here</h4>
  </div>
<% end %>

John W. Long

unread,
Mar 26, 2014, 10:55:13 PM3/26/14
to serve...@googlegroups.com
Try putting an equals sign in front of the yield! :)

Instead of:

    <% yield :jumbotron %>

Write:

    <%= yield :jumbotron %>

—John

--
--
Serve Users Group
Mailing List: http://groups.google.com/group/serve-users/
Project: http://github.com/jlong/serve/

---
You received this message because you are subscribed to the Google Groups "Serve Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to serve-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael McLaughlin

unread,
Mar 26, 2014, 10:57:20 PM3/26/14
to serve...@googlegroups.com
ok, I think I found something. it's called capture and explained here: http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html

If i'm understanding it correctly, it does basically the same thing that the content_for method does in rails except it just stores it in a variable.

Michael McLaughlin

unread,
Mar 26, 2014, 10:59:17 PM3/26/14
to serve...@googlegroups.com
crap. that might work too ;P
Just tried it. it worked.

John W. Long

unread,
Mar 26, 2014, 10:59:28 PM3/26/14
to serve...@googlegroups.com
Well capture is for building your own helpers like content_for. But you don’t need that. content_for is part of Rails. See:


You use it just like the examples there.

—John

John W. Long

unread,
Mar 26, 2014, 11:00:03 PM3/26/14
to serve...@googlegroups.com

On Mar 26, 2014, at 10:59 PM, Michael McLaughlin <michael.j.m...@gmail.com> wrote:

crap. that might work too ;P
Just tried it. it worked.

Easy mistake. Happens to me all the time. :)

—John

Michael McLaughlin

unread,
Mar 26, 2014, 11:06:58 PM3/26/14
to serve...@googlegroups.com
yeah, ok. now that i've taken a 5 minute break and will soon be shamed by anyone who has ever written ruby, I now have some perspective. 
After rereading that capture description again, that description, as well as the name itself makes a bit more sense.
Reply all
Reply to author
Forward
0 new messages