Insomania Insomania - 4 months ago 8
Ruby Question

How to comment Multiple lines in rails 5 controller?

Hi i am trying to comment multiple lines in rails 5 controller, i have googled alot and found the following solution: "=begin"

=begin (Multiple lines)
respond_to do |format|
if @person.update_attributes(params[:person])
flash[:notice] = 'Person was successfully updated.'
format.html { redirect_to(@person) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
end
end
=end


but it gives this error syntax error, unexpected '=' =begin

Please help me to sort out this issue.

Note: I am using Rails 5.0

Answer

Ruby multi line comments only work when there is no whitespace between the start of the line and the =begin (the same applies to the =end). Make sure the line starts with =begin:

This works:

=begin
  foo
  bar
=end

This won't work:

  =begin
    foo
    bar
  =end