Rail Devise sign_up / forgot_password在同一视图中 - 错误

时间:2015-03-19 01:57:56

标签: ruby-on-rails devise

我有一个signin视图,其中包含我重命名为的设计默认视图中的两个部分: 1. _sign_in.html.erb 2. _forgot.html.erb

我正在覆盖设计密码控制器:

class PasswordsController < Devise::PasswordsController
  def create 
  # super

  self.resource = resource_class.send_reset_password_instructions(resource_params)
  yield resource if block_given?

  if successfully_sent?(resource)
   respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
  else
   render signin_path

   # Original redirect
   # respond_with(resource)
  end
 end
end

部分代码:

<%= simple_form_for(resource, as: resource_name, url: user_password_path(resource_name), html: { method: :post }) do |f| %>
  <%= f.error_notification %>

   <div class="form-inputs">
   <%= f.input :email, required: true, autofocus: true, placeholder: 'Please enter your email address', label: false %>

   <div class="form-actions">
     <%= f.button :submit, "Send me instructions to reset my password ", class: "btn-wide secondary" %>
    </div>
<% end %>

以下是signin.html.erb视图,其中两个部分都来自:

<div class="hero">
  <%= image_tag("key-logo.png", :class => "logo", :alt => "key-logo") %>
  <h1>App.title</h1>
  <div class="sign-in">
    <%= render "devise/sessions/sign_in" %>
  </div>
</div>
<div class="sign-up">
  <div class="intro">
    <h1><a name="signupform">Forgot your password?</a></h1>
    <h3>Don't worry it happens to the best of us. We got this.</h3>
    <h5>Just enter your email in the form below and you're set!</h5>
  </div>
  <div class="row">
    <div class="forgot">
      <%= render "devise/passwords/forgot" %>
    </div>
  </div>
</div>

我已按顺序配置路线:

Rails.application.routes.draw do
  devise_for :users, controllers: {
    registrations: 'registrations',
    passwords: 'passwords'
  }

  get 'pages/index'
  get 'docs', to: 'pages#docs', as: 'docs'
  get 'signin', to: 'pages#signin', as: 'signin'

  root to: 'pages#index'
end

我已将application.helper中的设计用户范围配置为:

module ApplicationHelper
    # Fix to get devise forms working within the application scope and not just the gem:
  # http://pupeno.com/2010/08/29/show-a-devise-log-in-form-in-another-page/
  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

  def day
    @day = Time.now
    @day.strftime('%A')
  end

end

当我提交时,我收到了错误的模板错误:

Missing template /signin with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: *

我知道devise规范声明在views目录中重新创建相应的视图。我试过了,仍然得到了错误。我想知道它是否是表单命名空间的问题。我使用simple_forms来呈现我的表单。

1 个答案:

答案 0 :(得分:0)

这是路线中的问题

get 'signin', to: 'pages#signin', as: 'signin'

当我把它改回原来的

get 'pages/signin'

它有效