Pass ‘_’ as parameter to parameterize(separator: ‘-‘). For Rails 4 and below, use str.parameterize('_')
Examples:
with space
str = "New School"
str.parameterize(separator: '_')
=> "new_school"
without space
str = "school"
str.parameterize(separator: '_')
=> "school"
You can also solve this by chaining underscore to parameterize.
Examples:
with space
str = "New School"
str.parameterize.underscore
=> "new_school"
without space
str = "school"
str.parameterize.underscore
=> "school"