I have a signin view that contains two partials from the devise default views that I renamed as: 1. _sign_in.html.erb 2. _forgot.html.erb
I am overriding the devise passwords controller:
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
The partial code:
<%= 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 %>
Here is the signin.html.erb view that both partials are rendered from:
<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>
And I've configured the routes accordlingly:
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
I've configured the devise user scope in application.helper as:
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
When I submit I am getting a missing template error:
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: *
I know the devise specs state to re-create the corresponding view in the views directory. I've tried that and still get the error. I wondered if it was a problem with the form namespace. I am using simple_forms to render my forms.
It was a problem with this in the routes
get 'signin', to: 'pages#signin', as: 'signin'
when I changed it back to the original
get 'pages/signin'
it worked
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.