2010-11-25 6 views
41

Я установил Devise для моего приложения Rails (3.0.1), и он работает в основном. Я просто , похоже, не может настроить настройки почтового ящика.Ruby/Rails: Как вы настраиваете шаблоны почтовой рассылки Devise?

  • Моя модель пользователя «Пользователь».
  • Контроллеры DEViSE (которые мне нужно было отменить, так что я мог бы сказать, что контроллеры файл макета для использования) в app/controllers/users/, как и app/controllers/users/sessions_controller.rb
  • разработать взгляды (которые я отредактирован) в app/views/users/ как так app/views/users/registrations/new.html.haml
  • Вот Разрабатывают часть моего файла маршрутов:
 
    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 

Все выше работ, по крайней мере. Однако при отправке почты шаблоны, которые, как представляется, используют Devise, не те, что я редактировал на app/views/users/mailer/. Похоже, что Devise по-прежнему подходит по умолчанию (как будто я никогда не редактировал файлы). Я предполагаю, что Devise по-прежнему использует файлы в драгоценном камне.

В случае помогает, вот ошибка Огурцы:

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 "[email protected]"                   # 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 [email protected]!</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 "[email protected]"                   # 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 

и приложение/просмотров/пользователей/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> 

Кроме того, если это помогает, вот контроллеры I 'over overed:

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

Как исправить эту проблему?

Спасибо!

ответ

57

Думаю, вам нужно будет самостоятельно управлять представлениями. Выполните следующие действия в консоли:

rails generate devise:views 

Это произведет все виды Придумайте использование (включая шаблоны почтовой программы), которые вы можете настроить.

почтовые программы, которые вы ищете, то должны быть в «приложение/просмотров/изобрести/почтовик»

+0

Я запутался - так как все мои вещи находятся под пространством имен пользователей, должны ли представления быть под «app/views/users /»? Это то, что у меня есть сейчас, и когда я редактирую представления для другого материала (например, приложения/представления/пользователи/регистрации), он отражает изменение в моем приложении. * Не * просмотр приложений/просмотров/пользователей/мейкеров. – 2010-12-03 02:48:14

+1

Кажется, у вас есть шаблоны почтовой рассылки в нужном месте. Посмотрите на эту тему http://groups.google.com/group/plataformatec-devise/browse_thread/thread/98cdb37ac52bdf51, может быть, она может указать вам в правильном направлении? – 2010-12-04 23:11:38

0

Попробуйте это:

rails generate devise:views 
20

согласно devise's docs

вы должны отредактировать конфигурационный /initializers/devise.rb:

config.scoped_views = true 

(комментируется по умолчанию)

, делая это, вы можете настроить свои представления для разных моделей, а не для глобального устройства.

22

Сформировать видом от имени ресурсов

rails generate devise:views users 

Чтобы генерировать указать взгляды на модуль из recoverable

rails generate devise:views users -v passwords 

Сформировать указать почту просмотров только

rails generate devise:views users -v mailer 

для получения более подробной информации generate views

Смежные вопросы