content_for

已查看 13 次
跳至第一个未读帖子

Michael McLaughlin

未读,
2014年3月26日 22:47:482014/3/26
收件人 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

未读,
2014年3月26日 22:55:132014/3/26
收件人 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

未读,
2014年3月26日 22:57:202014/3/26
收件人 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

未读,
2014年3月26日 22:59:172014/3/26
收件人 serve...@googlegroups.com
crap. that might work too ;P
Just tried it. it worked.

John W. Long

未读,
2014年3月26日 22:59:282014/3/26
收件人 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

未读,
2014年3月26日 23:00:032014/3/26
收件人 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

未读,
2014年3月26日 23:06:582014/3/26
收件人 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.
回复全部
回复作者
转发
0 个新帖子