There are multiple barcode generator gems available, i decided on 'barby'
First I adding barby to the Gemfile file and using bundler to download and install said gem
Then I had to add the needed 'require' lines to controllers and views using barby. Code-128 is the type of barcode I needed to use.
require 'barby'
require 'barby/barcode/code_128'
Finally using the following lines of code I generated the barcode as a PNG and saved it into a file:
@barcode = Barby::Code128.new("1234")
outputter = Barby::PngOutputter.new(@barcode)
outputter.xdim = 2
File.open('barcode.png','wb') {|f| f.write outputter.to_png }
Apparently in Rails you need to manually set the MIME-Type of attachments, otherwise their filesize, filetype and other Metadata are not properly recognized by the E-Mail client and images will not be displayed within the html e-mail.
In this case using the hash :mime_type and the corresponding value 'image/png' in the rails controller solved this problem:
attachments.inline["img.png"] = {:data => File.read('img.png'), :mime_type => 'image/png'}