Perl to rewrite label to label_for

After quickly scaffolding, you may find you want to actually use portions of the generated form _form.rhtml. If you’re using technoweenie’s labeled_form_helper plugin, the following Perl will quickly convert each label element into something more suitable.

$ perl -i -pe "s##<%= label_for(\"\$1\", \"\$2\", :text => '\$3') %>#g" \
  app/views/test/_test_form.rhtml

Before and after.


<%= label_for("inquiry", "email", :text => 'Email') %>

And, if you don’t care about adding your own label text, you can omit the expression that creates :text entirely and label_for will just use the column name.

Post a Comment

Your email is never shared. Required fields are marked *

*
*