我觉得这很容易......
我对默认的Devise控制器进行了很少的自定义,我的注册#New中的自定义旨在确保在视图中可以访问某些变量。我已阅读了源代码,但如果访问注册页面的用户已登录,我不确定是否看到重定向用户的行?
基本上,如果用户已经登录,如果他/她访问了注册页面,我想将他/她重定向到仪表板页面。目前,重定向将转到根页面。
我该怎么改变?
我的代码:
class Users::RegistrationsController < Devise::RegistrationsController
def new
gon.zipcode_list = zipcode_list
gon.all_invite_codes = all_invite_codes
selected_plan_array
meal_type_array
super
end
end
源代码:
def new
build_resource({})
set_minimum_password_length
yield resource if block_given?
respond_with self.resource
end
路线:
devise_for :users, controllers: { registrations: "users/registrations", sessions: "users/sessions" }
root "staticpages#home"
#^ the above is where a user is being redirected if s/he is already signed in and visiting the sign up page
基本上我喜欢下面的内容
def after_existing_sign_in_path_for(resource)
dashboard_path
end
答案 0 :(得分:5)
重定向用户的源代码中的代码是filter:require_no_authentication。如果您覆盖Devise :: SessionsController以跳过该过滤器,您将能够将您的用户重定向到您选择的路径。
像这样:
/** Extract a text string in double quotes from the formulas in selected cells
*/
function replaceFormulasWithFirstQuotedTextStringInFormula() {
// Goes through all the cells in the active range (i.e., selected cells),
// checks if a cell contains a formula, and if so, extracts the first
// text string in double quotes in the formula and stores it in the cell.
// The formula in the cell is replaced with the text string.
// see https://productforums.google.com/d/topic/docs/ymxKs_QVEbs/discussion
// These regular expressions match the __"__ prefix and the
// __"__ suffix. The search is case-insensitive ("i").
// The backslash has to be doubled so it reaches RegExp correctly.
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp
var prefix = '\\"';
var suffix = '\\"';
var prefixToSearchFor = new RegExp(prefix, "i");
var suffixToSearchFor = new RegExp(suffix, "i");
var prefixLength = 1; // counting just the double quote character (")
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeRange = ss.getActiveRange();
var cell, cellValue, cellFormula, prefixFoundAt, suffixFoundAt, extractedTextString;
// iterate through all cells in the active range
for (var cellRow = 1; cellRow <= activeRange.getHeight(); cellRow++) {
for (var cellColumn = 1; cellColumn <= activeRange.getWidth(); cellColumn++) {
cell = activeRange.getCell(cellRow, cellColumn);
cellFormula = cell.getFormula();
// only proceed if the cell contains a formula
// if the leftmost character is "=", it contains a formula
// otherwise, the cell contains a constant and is ignored
// does not work correctly with cells that start with '=
if (cellFormula[0] == "=") {
// find the prefix
prefixFoundAt = cellFormula.search(prefixToSearchFor);
if (prefixFoundAt >= 0) { // yes, this cell contains the prefix
// remove everything up to and including the prefix
extractedTextString = cellFormula.slice(prefixFoundAt + prefixLength);
// find the suffix
suffixFoundAt = extractedTextString.search(suffixToSearchFor);
if (suffixFoundAt >= 0) { // yes, this cell contains the suffix
// remove all text from and including the suffix
extractedTextString = extractedTextString.slice(0, suffixFoundAt).trim();
// store the plain hyperlink string in the cell, replacing the formula
cell.setValue(extractedTextString);
}
}
}
}
}
}
/** Add a custom menu to the active spreadsheet, containing a single menu item
* for invoking the replaceFormulasWithFirstQuotedTextStringInFormula() function.
* The onOpen() function is automatically run when the spreadsheet is opened.
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Replace formulas with text strings",
functionName : "replaceFormulasWithFirstQuotedTextStringInFormula"
}];
ss.addMenu("Extract", entries);
}