I have a basic custom generator that looks like this, that inherits from Rails::Generators::NamedBase in a Rails 5.1 app
class NotificationGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
def notification
copy_file "notification.rb", "app/notifications/#{file_name}.rb"
copy_file "notification_spec.rb", "spec/notifications/#{file_name}_spec.rb"
end
end
My template file is called notification.rb.tt which lives under the ../templates directory.
The template looks like this:
class <%= class_name %> < Notification
def to_mail
end
def to_sms
end
end
However when I run the generator the created files have <%= class_name %> in the file rather than the result of that method call. How do I get the generator to actually render like an erb template?