devise

Devise redirect back on sign up failure with validations

自闭症网瘾萝莉.ら 提交于 2019-12-23 14:59:09
问题 I have a simple Devise registration form with the validatable plugin. It mostly works as intended, if the user forgets to enter a first name it redirects them back with a red validation message. The problem is it redirects to the same path a successful login would have the user go to (i.e. it redirects them to /user and not back to /user/sign_up ). If the user then refreshes the page for whatever reason they get a No route matches [GET] "/user" error. How can I force a redirect to go back to

Devise authentication error with ActionController::Responder and axlsx_rails gem

◇◆丶佛笑我妖孽 提交于 2019-12-23 13:31:33
问题 Added an export-to-xlsx option with the axlsx and axlsx_rails gems to an existing Rails 4.2.0 app that uses Devise for authentication. Export to xlsx now works properly: app/controllers/cases_controller.rb: class CasesController < ApplicationController def create ⋮ @public_fields = public_fields respond_to do |format| ⋮ format.xlsx { render :xlsx => "create", :filename => "cases.xlsx" } end end end app/views/cases/create.xlsx.axlsx: wb = xlsx_package.workbook wb.add_worksheet(name: 'Cases')

how to hook for destroy of a model that belongs to another model?

巧了我就是萌 提交于 2019-12-23 12:51:48
问题 I have a User model which has_many experiments: class User < ActiveRecord::Base has_many :experiments, :dependent => :destroy and Experiment model: class Experiment < ActiveRecord::Base belongs_to :user has_attached_file :thumbnail I want to hook for destroy moment at the Experiment model after the owner User get destroyed. (ex user cancel his account) I need to do so to delete the attachment image of the Experiment model, which is stored at amazon. like experiment.thumbnail.destroy What is

How to get rid of email regex message on Devise?

一世执手 提交于 2019-12-23 12:16:41
问题 I'm using Devise Token Auth gem and, everytime I run my test suite in Rails 4.2.5 app, I'm getting this deprecation warning from Devise: DEPRECATION WARNING: [Devise] config.email_regexp will have a new default on Devise 4.1 To keep the current behavior please set in your config/initializers/devise.rb the following: Devise.setup do |config| config.email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/ end If you want to use the new default: Devise.setup do |config| config.email_regexp = /\A[^@\s]+@

Warden authentication recalls 401 Unauthorized

梦想的初衷 提交于 2019-12-23 12:15:32
问题 i tried setting up devise with a brand new rails app, i have devise installed correctly using the gemfile and bundle install following that installed devise using rails generate devise:install created a new model using rails generate devise user rake db:migrate to create the user table added devise_for :users do get 'users/sign_out', :to => 'devise/sessions#destroy' end for signing out with my browser run rails server go to localhost:3000/users/sign_up to create a new user go to localhost

“WARNING: Can't verify CSRF token authenticity” error - CORS with Devise and :token_authenticatable

爷,独闯天下 提交于 2019-12-23 11:49:09
问题 I have a single page app that authenticates to another domain using CORS. All the requests are JSON requests. My app can authenticates OK and can make GET requests OK. Authentication is using token_authenticatable. I.e. all requests append '?auth_token=whatever' So, my actual problem is that when I try to do a PUT request I get a WARNING: Can't verify CSRF token authenticity message in the rails log as well as a CanCan::AccessDenied (You are not authorized to access this page.) exception.

Why is Devise's “current_user” not available at the model layer?

混江龙づ霸主 提交于 2019-12-23 10:03:17
问题 There are many posts about Devise and the lack of availability of "current_user" for use in models. There are numerous work arounds posted here and elsewhere. However, i haven't found the answer to "why" in any of the posts. Is this a security issue? If not, why? 回答1: Because you don't have access to a session variable inside a model, it's not a Devise issue or something related to security. It's related to the MVC pattern used in Rails. 来源: https://stackoverflow.com/questions/5884132/why-is

Rails: Calling Devise authenticate_user! and handling invalid user/password exception

浪尽此生 提交于 2019-12-23 09:47:49
问题 I have a popup that will only allow to view/save some information if the user is authenticated. I am using devise. In the controller before_filter it checks if user is signed in and if not, show a sign in page. This sign in page is ripped down version of the site's sign in page, so that it fits nicely to the popup. On the authenticate action I call authenticate_user!. Everything works fine when the user enters valid credentials. But when the credential is invalid, devise automatically

How do I add instance variables to Devise email templates?

雨燕双飞 提交于 2019-12-23 09:28:03
问题 I am trying to edit the confirmation_instructions.html.erb file to address the new user by first name instead of email. Current the beginning of the file reads... Hi, <%= @email %>, How do I add an instance variable @first_name to the controller/mailer? I ran rails generate devise:controllers users, but I just don't see any .rb files where I could add instance variables to confirmation mailer (if there is one) Thanks 回答1: This is easy, you can just create a Mailer for this: class

Adding confirmable module to an existing site using Devise

馋奶兔 提交于 2019-12-23 09:24:44
问题 I'm using devise for a web app and wanted to add the confirmable module to the site. However, since a confirmation_token isn't generated users can't sign in. When clicking the 'Didn't receive confirmation instructions?' link the token still isn't generated. Confirmation email just generates this link (notice the lack of token in the url): <p><a href="http://localhost:3000/users/confirmation">Confirm my account</a></p> What is the best way to get this to work? Many thanks, Tony 回答1: I'm