Rails has a method form_for which takes a &proc that contains the content present inside the generated form tag. For example, in HAML:
= form_for @my_model do |f|
= f.label :demo_field
= f.text_field :demo_field
I’d quite like to prepend something to that &proc block so that the form renders as
= form_for @my_model do |f|
%h1 Demo Of Breaking Into A Proc
= f.label :demo_field
= f.text_Field :demo_field
The question is, how do I go about prepending something to a proc argument? The method I’m calling is:
module ActionView::Helpers::FormHelper
alias_method :original_form_for, :form_for
def form_for(record, options = {}, &proc)
# Prepend to the proc block here
# ???
original_form_for(record, options, &proc)
end
end
If anyone could replace that “# ???” line with a solution (or offer an alternative approach if I’m going about this the wrong way), I’d be really appreciative.
You can’t change a
Proc.