Module: PasswordGenerator::ViewHelper

Defined in:
lib/password_generator/view_helper.rb

Overview

The ViewHelper module provides a helper method for generating random passwords in Rails views.

It is automatically included in the ActionView::Base class through the Railtie, making the random_password_tag method available for use in views.

Instance Method Summary collapse

Instance Method Details

#random_password_tag(length = 12) ⇒ String

Generates an HTML paragraph containing a randomly generated password.

Parameters:

  • length (Integer) (defaults to: 12) —

    The length of the password to generate. Defaults to 12.

Returns:

  • (String) —

    HTML paragraph tag containing the random password.



15
16
17
18
# File 'lib/password_generator/view_helper.rb', line 15

def random_password_tag(length = 12)
  password = PasswordGenerator.generate_password(length)
  (:p, "Password: #{password}")
end