Advanced Block Helpers

I have a site that calls for multiple content areas on a screen. In order to remain DRY I wanted to create a helper that helped reduce the markup.

At a high level I have a helper method that creates an instance of a ContentBlock class and calls render on it. I want to render everything inside the block passed to the helper method in the context of ContentBlock, so that I can do something like

content do |c|   c.tab do     'tab content'   end

  c.tab do     'other tab content'   end end

Right now when I do what I have posted in the gist below I get the following error:

undefined method `safe_concat' for nil:NilClass, I'm assuming that is because it tries to buffer the template code and execute it in the context of my content block class.

Here is the gist of what I am currently have: Content Block Class · GitHub Here is a mockup of the final product: Imgur: The magic of the Internet

I have a site that calls for multiple content areas on a screen. In order to remain DRY I wanted to create a helper that helped reduce the markup.

At a high level I have a helper method that creates an instance of a ContentBlock class and calls render on it. I want to render everything inside the block passed to the helper method in the context of ContentBlock, so that I can do something like

content do |c| c.tab do 'tab content' end

c.tab do 'other tab content' end end

Right now when I do what I have posted in the gist below I get the following error:

undefined method `safe_concat' for nil:NilClass, I'm assuming that is because it tries to buffer the template code and execute it in the context of my content block class.

Well you do evaluate the block by calling instance_eval on yourself, so your asking for it to be evaluated in the context of your ContentBlock object. You probably want all that to happen on the template object instead.

Fred