Ruby on Rails(Segmentation)

There is a piece of source code.On selection of some part of source code
and click on button say"Create Segment".Segment should be created.
Structure for this is:
/Start Segment1/
{



}
/End Segment1/

On clicking the create segment button, for the selected text start and
end segment should be created.Please help me to overcome this problem.