views:

27

answers:

2

Is it possible to save the output of a block of Rails code into a variable so I can output it in a number of places later on inside a view?

I realise layouts etc have yield, but I want to do this in a view (I'm generating a mail-merge-esque thing that has calculated elements that are the same in each letter)

A: 

You can def things inside your application_helper file to be available to all views.

ErsatzRyan
A: 

If it is a block of erb code, use capture. Otherwise you can use block.call to call the block as a normal function.

Ben Hughes