Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:46:01+00:00 2026-05-15T19:46:01+00:00

This is a helper method I found in the ruby on rails application spree

  • 0

This is a helper method I found in the ruby on rails application spree commerce.

I’m trying to better understand what’s going on here, particularly with the capture() method on line 12, which I’ve never seen before. If there is a block given, it captures it, otherwise there is no content. But where does capture() come from? what is it doing?

 11   def hook(hook_name, locals = {}, &block)
 12     content = block_given? ? capture(&block) : ''
 13     result = Spree::ThemeSupport::Hook.render_hook(hook_name, content, self, locals)
 14     block_given? ? concat(result.to_s) : result
 15   end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:46:02+00:00Added an answer on May 15, 2026 at 7:46 pm

    When you yield from a block in an ERB view (at least in rails 1.x and 2.x), it will write directly to the buffer and hence to the rendered html, which is probably not desired. Instead you can ‘capture’ the result of the evaluation of the block and assign it to a variable as they’ve done here. Anyway, I am probably not explaining it as well as Ryan Bates does here:

    http://railscasts.com/episodes/40-blocks-in-view

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you saw the railscasts on nested forms this is the helper method to
I'm going through Michael Hartl's Ruby on Rails 3.2 Tutorial and I'm confused about
I'm trying to write a helper method in JavaScript. It should act differently if
I'm trying to get the permit method to work using the rails-authorization-plugin and authlogic
I am creating a custom helper in ./application/helpers however i am getting this error
I'm trying to make tiny helper method for simplify routine operations But on the
I haven't found any native method to do this, so I created my own
I've found a helper method that I would like to use to resize embedded
I am trying to stub a method on a helper that is defined in
I'm using phonegap with application preferences plugin and trying to make a helper function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.