[Ruby-On-Rails] Ruby / Rails: come personalizzi i modelli di mailer di Devise?


Answers

secondo i documenti di devise

dovresti modificare la tua configurazione / inizializzatori / devise.rb:

config.scoped_views = true

(è commentato di default)

così facendo, puoi personalizzare le tue visualizzazioni per diversi modelli, piuttosto che per l'idea globale.

Question

Ho installato l'app Devise for my Rails (3.0.1) e funziona principalmente. Non riesco a personalizzare le visualizzazioni del mailer .

  • Il mio modello utente è "Utente".
  • I controller di sviluppo (che avevo bisogno di sovrascrivere per poter dire ai controller quale file di layout utilizzare) sono in app/controllers/users/ , come app/controllers/users/sessions_controller.rb
  • Le viste elaborate (che ho modificato) sono in app/views/users/ like così app/views/users/registrations/new.html.haml
  • Ecco la porzione elaborata del mio file di percorsi:
    devise_for :users, :controllers => { 
      :sessions => "users/sessions", 
      :registrations => "users/registrations", 
      :passwords => "users/passwords", 
      :confirmations => "users/confirmations", 
      :unlocks => "users/unlocks"
    } do
      get "/login" => "devise/sessions#new"
      get "/logout" => "devise/sessions#destroy"
    end

Tutto sopra funziona, almeno. Tuttavia, quando si invia la posta, i modelli che Devise sembra utilizzare non sono quelli che ho modificato in app/views/users/mailer/ . Devise sembra ancora riprendere quello predefinito (come se non avessi mai modificato i file). Immagino che Devise usi ancora i file nella gemma.

Nel caso in cui aiuta, ecco l'errore Cucumber:

Feature: Manage accounts
  In order to manage accounts
  users
  should be able to signup

  # By default, www.example.com is the host when testing.
  # This is a problem because when our site searches for the domain example.com, it cant find any.
  # Therefore we must either set our testing domain to one of our choosing (and mention that in the routes), or create a domain example.com
  # I prefer the first option.
  Scenario: Signing up and resetting the password                                                                      # features/manage_accounts.feature:10
    Given I am on the login page                                                                                       # features/step_definitions/web_steps.rb:19
    When I follow "Sign up"                                                                                            # features/step_definitions/web_steps.rb:33
    And I fill in "Login" with "bobrobcom"                                                                             # features/step_definitions/web_steps.rb:39
    And I fill in "Email" with "my@email.com"                                                                          # features/step_definitions/web_steps.rb:39
    And I fill in "Password" with "123456"                                                                             # features/step_definitions/web_steps.rb:39
    And I fill in "Password confirmation" with "123456"                                                                # features/step_definitions/web_steps.rb:39
    And I press "Sign up"                                                                                              # features/step_definitions/web_steps.rb:27
    Then I should see "Your account has been created. A confirmation was sent to your e-mail."               # features/step_definitions/web_steps.rb:107
    And I should receive an email                                                                                      # features/step_definitions/email_steps.rb:51
    When I open the email                                                                                              # features/step_definitions/email_steps.rb:72
    Then I should see "Welcome bobrobcom!" in the email body                                                           # features/step_definitions/email_steps.rb:96
      expected "<p>Welcome my@email.com!</p>\n\n<p>You can confirm your account through the link below:</p>\n\n<p><a href=\"http://stils.dev/users/confirmation?confirmation_token=d9ZXliqfTArb2cNmwPzL\">Confirm my account</a></p>\n" to include "Welcome bobrobcom!" (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/email_steps.rb:97:in `/^(?:I|they) should see "([^"]*?)" in the email body$/'
      features/manage_accounts.feature:21:in `Then I should see "Welcome bobrobcom!" in the email body'
    When I follow "Confirm my account"                                                                                 # features/step_definitions/web_steps.rb:33
    Then I should see "Your account was successfully confirmed. You are now signed in."                                # features/step_definitions/web_steps.rb:107
    When I log out                                                                                                     # features/step_definitions/user_steps.rb:9
    And I go to the reset password page                                                                                # features/step_definitions/web_steps.rb:23
    And I fill in "Email" with "my@email.com"                                                                          # features/step_definitions/web_steps.rb:39
    And I press "Send me reset password instructions"                                                                  # features/step_definitions/web_steps.rb:27
    Then I should see "You will receive an email with instructions about how to reset your password in a few minutes." # features/step_definitions/web_steps.rb:107
    And I should receive an email                                                                                      # features/step_definitions/email_steps.rb:51
    When I open the email                                                                                              # features/step_definitions/email_steps.rb:72
    Then I should see "Hello bobrobcom!" in the email body                                                             # features/step_definitions/email_steps.rb:96
    When I follow "Change my password" in the email                                                                    # features/step_definitions/email_steps.rb:166
    Then I should see "Set your new password"                                                                          # features/step_definitions/web_steps.rb:107

Failing Scenarios:
cucumber features/manage_accounts.feature:10 # Scenario: Signing up and resetting the password

E app / views / users / confirmation_instructions.erb:

<p>Welcome <%= @resource.login %>!</p>

<p>You can confirm your account through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

Inoltre, se aiuta, ecco i controller che ho scavalcato:

| | |~users/
| | | |-confirmations_controller.rb
| | | |-passwords_controller.rb
| | | |-registrations_controller.rb
| | | |-sessions_controller.rb
| | | `-unlocks_controller.rb

Come posso risolvere questo problema?

Grazie!




Prova questo:

rails generate devise:views



Links