Devise sign_out action not working - ruby-on-rails

Ruby 1.8, Rails 2.3.15, devise 1.0.10 and warden 0.10.3
I have implemented admin using this example: https://github.com/plataformatec/devise/tree/v1.0. When I sign out it show the message but I can still acess those page without signing in again. Can anyone let me know what is wrong with it.
Thanks in advance.

SInce you have not added any code, I can just guess that you have missed out the before filter:
before_filter :authenticate_user!
use this in the controller abouve all methods, this method is available by devise.

Related

Devise getting 401 unauthorized right after sign in

Rails 4.2, Ruby 2.2.0, Devise 3.5.7
I have an Admin model. In ideal case after sign in, it should be redirected to homepage. But in my case, it is signing in successfully, but while redirecting, somehow authentication fails, causing it to redirect to the sign in page again.
The controller which gets called is:
Class Admin::DashboardsController < ApplicationController
before_action :authenticate_admin!
before_filter :authorize
def show
end
end
In first view, I thought it is a problem with authorize method. But code never reaches it.
authenticate_admin! is a devise method. And I don't know if there is a point in debugging.
Surprisingly it works on local, but results in 401 Unauthorized after deploying.
Logs
I think the application is fine. It has to do something with your server configurations. Something might be missing.
As you said it is working locally, there might be something that you changed in your configurations for the server, that might be causing the problem. Check your config files, application.rb or any other subdomain files that you might be using.

problems with sign out, cookies and devise on rails

I have been trying to sign in after signing out on my application using devise but I am having an issue with the cookies I think because I have to refresh my web page in order to sign in again. I tried using activerecord-session_store gem and I follow the steps to configure it. I mean, I installed the gem, I generated the recommended migration on the gem documentation and generated the table using rake db:migrate command, I also changes the session_store.rb file but I feel that I am missing something to make it work since I tried it and the same happens. Please help me if you feel I am missing something or if you have other solution for this problem. Many thanks in advance
You are probably getting a "Can't verify CSRF token authenticity" error. Can you check your server logs?
In your ApplicationController please add the following and check if you get an error.
protect_from_forgery with: :exception

Where is the code that Devise generates?

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.

How upgrade devise 2.1.2 to devise 3.2.2

I want to upgrade my current devise from 2.1.2 to 3.2.2
I added the secret_key to the initialiser so the rails server starts fine.
But when I try to login I can't. Examining the logs didn't make me any smarter.
I just get a 401 Unauthorized exception in the Rails log.
Can anybody give direction how to upgrade? Or how I could debug this a little bit better?
Maybe you should check your sign in field. if you follow devise guide (https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address), your sign in field should be "login", not "email"

Devise error using rails 3.0.1 on sign_in action

I'm developing a rails 3 app using rails 3.0.1 and I'd like to use devise for user auth, but when I login with a user email, I get this error:
RuntimeError in Devise/sessionsController#create
In order to use respond_with, first you need to declare the formats your controller responds to in the class level
I installed devise using Gemspec.
I have the same issue yesterday and today i up a ticket and they fix the problem. Make a bundle update to have the fix version.
Make sure this is the first entry in your routes file
devise_for :users
Consider upgrading to Rails 3.0.3

Resources