Martí Bosch Martí Bosch - 4 years ago 138
Ruby Question

devise custom user attribute acessors

I'm new to rails and I'm trying to customize the authetication.

I've done a custom confirmation mail view

as follows:

<p>Welcome <%= @email %>!</p>
Thanks for registering. You have registered through <%= @resource.provider %>.
The account data has been created automatically as follows:
<li><strong>User Name:</strong> <%= %></li>
<li><strong>Password:</strong> <%= @resource.password %></li>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

returns a string such as

If I wanted to customize these strings, let's say print instead
…, how should I do it? My first idea is a method

def print_cool_provider(provider)
if provider == 'facebook'
return 'Facebook'
else if ...

I consider a finite short list of possible providers that I can handle one by one. My real questions go more with MVC, Rails and Devise:

Where should I define this method to respect the MVC pattern and at the same time be able to call it from the

Answer Source

You could add a simple helper, like so:

# app/helpers/provider_helper.rb
module ProviderHelper

  # only special cases, where #titlecase won't suffice
    'github'        => 'GitHub',
    'google_oauth2' => 'Google'

  def provider_name(user)
    PROVIDER_NAMES[user.provider] || user.provider.titlecase

A better approach would be a presenter (or decorator), though.

N.B.: I would not submit the password via email, unless it is encrypted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download