plataformatec/devise — Issue #1633: Adding more values available to i18n
Author: ramontayag
Created: 2012-02-09 14:45:43+00:00
State: open

I can't seem to find an easy way to create a message like this when a user logs in: "Hey, Ramon!" Searching for "devise set_flash_message" doesn't yield any results with an easy solution.

What do you think about adding more exposed fields to the Devise model?

## devise.rb initializer

# `scope`, `default`, and `resource_name` are already set by Devise. To add more fields,
# add them below
config.extra_exposed_model_methods_for_i18n = [:first_name, :last_name, :email]

That means the `set_flash_message` will look more like this:

def set_flash_message(key, kind, options={})
options[:scope] = "devise.#{controller_name}"
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name

# Add the extra methods to options here
Devise.extra_exposed_model_methods_for_i18n.each do |method_name|
options[method_name] = resource.send(method_name)
end

message = I18n.t("#{resource_name}.#{kind}", options)
flash[key] = message if message.present?
end

With this, I should be able to use

devise:
sessions:
create: "%{first_name}, that's totally awesome!"

What do you think? Do you recommend another way?