我已经为我的Rails应用程序(3.0.1)安装了Desive,它基本上正常工作.我才can't seem customize the mailer views岁.

  • 我的用户模型是"用户".
  • Desive控制器(我需要重写它,以便告诉控制器要使用什么布局文件)是app/controllers/users/个,比如so app/controllers/users/sessions_controller.rb
  • Desive视图(我已经编辑过)有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

至少上面的一切都是有效的.然而,当发送邮件时,the templates that Devise seems to use aren't the ones I've edited at 100.Desive似乎仍然 Select 默认的一个(好像我从未编辑过这些文件).我猜Desive仍在使用gem中的文件.

如果有帮助,这里有一个错误:

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

以及应用程序/视图/用户/确认说明.雇员再培训局:

<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>

此外,如果有帮助,以下是我覆盖的控制器:

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

如何解决此问题?

谢谢

推荐答案

我认为你需要自己管理Desive视图.在控制台中try 以下操作:

rails generate devise:views

这将生成Desive使用的所有视图(包括mailer模板),您现在可以自定义这些视图.

你要找的邮件应该在app/views/devise/mailer中

如果您想生成范围视图,或者只生成其中的一个子集,这也是可能的.根据https://github.com/plataformatec/devise#configuring-views页的文档:

还可以使用生成器生成范围视图:

rails generate devise:views users

如果您只想生成几组视图,比如可注册和可确认模块的视图,那么可以将模块列表传递给带有-v标志的生成器.

rails generate devise:views -v registrations confirmations

Ruby-on-rails相关问答推荐

确定当前太平洋时区是PST还是PDT

Ruby on Rails - 外键不匹配

在 Rails 7 中,可以将导入映射与 js Bundle 解决方案一起使用,还是它们是专有的?

为什么 Image_tag 产生images/...而不是assets/....?

如何在 Rails 中注释掉 ERB?

在 Rails 3.2 中更新多行

Ruby/Rails 中的类方法与常量

在允许用户使用设计(rails)登录之前判断用户是否处于活动状态

RSpec 设置会话对象

Rails 在关联模型中排序

在 Windows 上安装特定的 Ruby on Rails 版本

在 Controller 中调用模型方法

批量查找 mongoDB 记录(使用 mongoid ruby​​ 适配器)

连接表的最佳 SQL 索引

使用 rvm 更新 ruby​​ 版本后收到警告消息Path set to RVM

Rails:带参数的 URL/路径

Rails 4,Capistrano 3.0.0,无法加载这样的文件 - 部署

Ruby on Rails:如何为 postgresql 编辑 database.yml?

如何在两个字段上对 ruby​​/rails 进行排序?

Rails:每个环境的初始化程序?