I'm using a non customized version of Devise in my app and am running into some issues with the reset password functionality.
The default reset password form's method is to PUT but upon submitting the form, it POSTs which causes it to give me an error about a missing email field. The POST/create method in the PasswordsController of Devise is emailing the user the password reset link. The PUT/update method is for the actual resetting of the password.
None of the devise stuff is altered in any way. Devise version is 3.5.7 and Rails is 4.2.6
I've put all of the relevant code in a Gist here: https://gist.github.com/dsarhadian/a7950e480bffc2906f77b0e542792f5a
Any help is truly appreciated...
In your logs it says:
Rendered devise/passwords/edit.html.erb within layouts/application (3.3ms)
Are you sure that the edit.html.erb file renders the form.html.erb view?
Because when I look at the source.html file, it seems like it is rendering a different form which has the path for the POST method.
The form.html.erb uses the PUT method. So it seems to me like the wrong form is rendered.
Related
I have what should be a very basic setup with the Recaptcha gem. It is showing all the appropriate on-page behavior: A recaptcha "I am not a robot" box appears on the sign up screen and is checkable by the user.
However, if I try and submit the sign in form without checking the box, it still goes through instead of showing an error message.
I followed the Gem's instructions pretty much verbatim:
I created the appropriate keys on Google's website and put them into
Heroku's variable storage successfully.
I put gem 'recaptcha' in my Gemfile and bundled.
I added <%= recaptcha_tags %> in my sign up form (Devise new user
registration).
I changed my create method to include if verify_recaptcha(model:
#user) && #user.persisted? in my registrations controller.
The box is showing up perfectly, but the user is able to create a new account even without checking the recaptcha box!
Can anyone see where I'm going wrong here? You can see the issue live here if you need to Google inspector it...
I am new to RoR and using rails5 on windows and used Devise Gem for authentication. I have to integrate HTML design for admin section. The problem is that whatever changes that i am making in /app/views/admins/sessions/new.html.erb file, they are not reflecting in the browser. I always see default login form of devise in which it shows Email and Password field with shared links.
Event by removing entire html from above new.html.erb file, i can still see login form.
I have tried executing below commands to clear cache but still i can not see my new html changes in the browser.
rake tmp:cache:clear
rake assets:clean
Not sure what else is required to make it working. Any help would be greatly appreciated
Running rails generate devise:views will generate all of the views that Devise uses. Editing the generated sessions/new.html.erb file should update the version you are seeing in the browser.
You can also delete any of the other generated files that you don't need to override.
Source:
https://github.com/plataformatec/devise#configuring-views
I installed the Devise gem into my Rails app, and ran rails generate devise:install and rails generate devise User.
Without my doing anything, the url users/sign_up already has a view somehow. The problem is, I can't find the template that is being rendered anywhere. It's certainly not under app/views/users. I chose some text on the page and ran a search for it within my app, and got back 0 results.
Then I tried to sign up with the form, and got the following error:
NoMethodError in Devise::RegistrationsController#create
undefined method `current_sign_in_ip' for #<User:xxxxxxxxxxx>
I then searched for this controller, but there is no RegistrationsController in my app, and no Devise file. None of the files I'm looking for were generated by the two commands I mentioned above, either.
The Devise documentation doesn't seem to shed any light on where the Devise code is kept.
Is the code even in my app? I'm so confused.
Using Devise, you're able to generate the templates which Devise depends on for logins, password resets, etc. using the following command:
rails generate devise:views
This will create copies of the templates for Devise in your views directory.
For controllers, you can access/override their functionality by subclassing them in your own code. They're under the Devise namespace:
class NewRegistrationsController < Devise::RegistrationsController
# do stuff here
end
Then point the router to use this new controller:
devise_for :users, controllers: { registrations: 'new_registrations' }
The code for the controllers can be found in Devise's source code - you can reference it to better understand what each controller is doing.
Hope that helps!
This is standard practice for Rails "engines" (which almost all gems are) -
Think of them as libraries / dependencies... wherein they provide access to a lot of pre-compiled functionality through several hooks (often provided by an API).
One of the reasons I'd actually recommend people to write their own gem is because it helps you appreciate how the whole thing works. I wrote a gem, it uses views just like Devise:
These views are not seen in the application because they're appended to your Rails app at runtime. It's basically how the PATH var works in cmd, if you've ever had the pleasure of working with programmatic compilation etc.
Thus, Devise's "views" are stored in the Devise gem. This is appended to your Ruby installation... [Ruby install dir]/lib/ruby/gems/[ver]/gems, loaded at RunTime just like the PATH var...
Whilst you can generate your Devise views (as mentioned in the other answers), this is the base line of how it's able to access them without any prior references.
NoMethodError in Devise::RegistrationsController#create
undefined method `current_sign_in_ip' for #<User:xxxxxxxxxxx>
This means you don't have the current_sign_in_ip attribute for your Devise installation. I answered your question about this specifically here...
Devise error: undefined method `current_sign_in_ip'
All the devise MVC files are inside the gem. Below is my devise views directory. You could check yours as well. Go to your project root.
gem show 'devise'
/Users/saurabh/.rvm/gems/ruby-2.1.0/gems/devise-3.2.4
cd /Users/saurabh/.rvm/gems/ruby-2.1.0/gems/devise-3.2.4/app/views
You can generate views in your project if you wish to customize.
rails generate devise:views
All code of devise can be easily go through by devise and if you are using rubyMine you can view devise code in external libraries in devise folder.
To generate template for your model
rails generate devise:views
and then you can change your view as you want for your application.
I have this new Rails app. I installed Devise. I don't want people registering for new accounts so I deleted the appname/app/views/devise/registrations/new.html.erb file
but when I try to access the delete page, I should get a "no routes" error or something similar, but instead, Rails looks for the Sign Up page here /gems/ruby-1.9.2-p290/gems/devise-1.5.2/app/views/devise/registrations/new.html.erb
I don't want the sign up page to be accessible.
You should remove the :registerable symbol from the list of devise stuff in your User model. This will disable the sign up feature.
I'm using devise for user auth, but I have nice mockups for the signup, login, etc. pages.
I've already done the rails generate devise:views User command and have all of the views in the views folder, however, when I replaced the registration/new.html.erb with my own new.html.erb, nothing changes nor looks different. It's as if I had done anything.
Anyone know what I'm doing wrong or at least how to successfully customize devise views
P.S. Is it important to note that I changed the route of devise/registration#new to /signup?
at a glance answer.
...instead of
rails generate devise:views User
use:
rails generate devise:views
If you've already done it, move the folders devise created from app/views/User to a new folder app/views/devise (or just rename the User folder to devise, if that's an option.)
Those folders are:
app/views/User/confirmations
app/views/User/mailer
app/views/User/passwords
app/views/User/registrations
app/views/User/sessions
app/views/User/shared
app/views/User/unlocks
No other changes are necessary.
though this is an old question, I thought I'd add to it in case anybody stumbles on it. I'm not sure if this is a new addition since the question was originally asked but if so the simpler (more modern) approach is this.
in the file config/initializers/devise.rb there is the following block of code:
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
by uncommenting config.scoped_views = false and changing it's value to true, devise will automatically check whether the custom view exists and if so, serve that up.
As the comment says, it may add some overhead to the application but in my experience so far, this is negligible.
Your route signup or devise/registrations#new will render the view
views/devise/registrations/new.html.erb. It sounds like you made
changes to views/user/registrations/new.html.erb, which would explain
why you dont see the changes made since its not being rendered.
You will either need to create a user/registrations_controller.rb that
extends from Devise::RegistrationsController and point your /signup
route to user/registrations#new, or you can just make your changes
directly to views/devise/registrations/new.html.erb
Same idea applies to your login (devise/sessions) pages.
Hope this helps.
For anyone still having a problem with this, the problem lies in the call to rails generate devise:views User. It should be rails generate devise:views for fetching current views from the Devise Rails Engine. This will generate proper views which will work with the default routes.
After generating your custom views e.g
rails generate devise:views User
Turn on scoped_views in config/initializer/devise.rb
view config.scoped_views = true
And you are done.
I had the same problem until I went back and read the devise documentation :)
After rails generate devise:views make sure you go into initializers/devise.rb and set config.scoped_views = true. This is explained in the devise documentation at https://github.com/plataformatec/devise as well as in the devise.rb comments.
After I did this, my own views in views/users started showing up instead of the ones in the gem.
Using rails g devise:views User allows you to customize when you have more than one role.
the proper way to do this is going into your devise.rb in config/initializer/ folder
and uncommenting and setting config.scoped_views = true.
now you can edit the view erb files without any problems
For future reference, you can just rename folder from devise => user and vice versa and rails will find a route.