Missing template with Devise custom registration controller - ruby-on-rails

When using recaptcha for Devise I have to make a new custom registrations controller and my issue is I get a missing template error when their is an error for the email, password or password confirmation because its hitting a route that doesn't even exist.
Template is missing
Missing template registrations/new
The recaptcha works on its own error and renders back to the same page but not for the others.
class RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha
super
else
flash.delete :recaptcha_error
build_resource
clean_up_passwords(resource)
flash[:alert] = "There was an error with the recaptcha code below."
render :template => '/devise/registrations/new'
end
end
end
devise_for :users, :controllers => { :registrations => "registrations" }
It should be hitting the same page the recaptcha does on errors ('/devise/registrations/new')How do I correct this issue?
Thanks.

Try moving the templates from /views/devise/registrations to just /views/registrations. (And changing the reference in your code from /devise/registrations/new to just /registrations/new.)

Add following line to your config/application.rb file
config.paths['app/views'] << 'app/views/devise'

Related

Remove :html reponse to Devise Passwords Controller

I would like to prevent users from accessing the html Devise page users/passwords/new, as I have made all my devise pages respond to :js.
It's all working for my Registrations and Sessions, but I can't seem to make it work with the Passwords.
I have set the routes to overwrite the controller:
devise_for :users, controller: { passwords: 'users/passwords' }
I have reset the navigational formats in that controller:
class Users::PasswordsController < Devise::PasswordsController
clear_respond_to
respond_to :js
****** rest of devise code
end
And I have set up devise.rb
config.navigational_formats = ['*/*', :html, :js] (even if I remove html here it still does not work)
I've even deleted new.html.erb from the views/devise/passwords folder.
But I still have access to the url users/passwords/new
Of course if I use a link with remote: true it does render my new.js.erb just like it should.
Also the fact that it only reponds to :js prevents Devise from working if I enter a mail in the field I get a ActionController::UnknownFormat error.
Anyone has ever done this before?
Well I think I've found a solution (?)
I just add this block in my confirmations_controller
def new
super
respond_to do |format|
format.js
end
end
So that users can still access the modal if the form is remote: true, but can't access the html version, because it raises an ActionController::UnknownFormat
Could this cause any further problems?

Rails: Use a custom URL for password reset with Devise

I am using Devise for authentication in my Rails app. The password management including reset password mailers, etc. is handled via a controller that derives from Devise::PasswordsController. Something like:
class Users::PasswordsController < Devise::PasswordsController
def new
if not set_actionmailer_settings
error = I18n.t('invalid_paswd_config')
redirect_to new_user_session_path,
:flash => { :error => error } and return
end
super
end
end
I have now moved to a new UI that does not use Rails UI. Instead it calls into the Rails APIs. In the email that is sent to the user for resetting password, if I want to use a use a custom password reset URL, how do I do it?
try this in your routes.rb
map.devise_for :users, controllers: {passwords: "users/passwords"}, path_names: {
new: :new
}

rails devise after_sending_reset_password_instructions weird behaviour

i want to redir to a page after sending reset pass instructions, so, by devise docu i added this to my password_controller
protected
def after_sending_reset_password_instructions_path_for(resource_name)
'buyers/sign_in'
end
in routes i have the
devise_for :buyers, :controllers => { :passwords => "passwords" }
and if i add 'puts 'xxxxxxx'' to the function i can even see this output in my server, but it wont REDIRECT to the path i m returning.
what s the problem?
in the end the problem was due to 'create' func was overloaded and changed severely(also calling super which didn't fit my needs), had to edit it and add this
if successfully_sent?(resource)
redirect_to new_partner_session_path
else
for it to work.

Setting up recaptcha with devise rails 3.1

I followed the devise wiki here and I get a template error when I try to create a new user. This is what I have done.
Set up my public and private keys in config/environment.rb
ENV['RECAPTCHA_PUBLIC_KEY']='examplepubkey'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'exampleprivkey'
I then added the gem to my gemfile and ran bundle install
gem 'recaptcha', :require => 'recaptcha/rails'
I then added a registrations controller by running rails g controller Registrations create and adding this to the file.
class RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha
super
else
build_resource
clean_up_passwords(resource)
flash[:alert] = "There was an error with the recaptcha code below. Please re-enter the code and click submit."
render_with_scope :new
end
end
end
I also added the recaptcha tags to views/devise/registrations/new
<div><%= recaptcha_tags %></div>
Then I edited the routes file to look like:
devise_for :users, :controllers => { :registrations => "registrations" }, :path => "users"
When I check out the link in my browser I get
Template is missing
Missing template registrations/new with {:handlers=>[:erb, :builder, :coffee],
:formats=>[:html], :locale=>[:en, :en]}. Searched in: *
"/Users/thomascioppettini/rails_projects/want_freight/app/views" *
"/Users/thomascioppettini/.rvm/gems/ruby-1.9.2-p180#standard/gems/devise-1.4.5/app/views"
[edit]
I was able to get the captcha to appear by deleting the bit I added about controllers, but the captcha passes when I add any text into the text field or leave it blank.
[edit2]
I was able to figure out how to solve the problem and will post the solution when stack overflow will allow me to.
I was able to get the recaptcha to work by destroying the controller I had set up using rails g controller Registrations create and adding the files by hand as this site suggests. setting up recaptcha with devise

Remove Devise Flash Notices for Sign out

As the name says, I am using devise for user auth in a rails 3 app
Upon user log out, there is a flash notice, "User Successfully signed out" that I don't want to appear. However, I can't figure out how to remove the notice.
Is there a way to get around just making it blank? I would like to completely remove the notice so that, ideally, there's not even an html div for notice
If you explicitly put in a blank string for this in your locale file, then Devise "won't bother" to render the message at all (e.g. there won't even be an empty HTML div).
#en.yml
devise:
sessions:
signed_in: 'Signed in successfully.'
signed_out: ''
My routes.rb
devise_for :users, :controllers => {
sessions: 'user/sessions'
}
My controller "account/sessions_controller.rb"
class User::SessionsController < Devise::SessionsController
def destroy
super
flash.delete(:notice)
end
end

Resources