constraints

Redirecting from routes when the constraints fail

送分小仙女□ 提交于 2019-12-08 17:28:10
问题 I want to redirect to a different url when the route constraint fails Route.rb match '/u' => 'user#signin', :constraints => BlacklistDomain blacklist_domain.rb class BlacklistDomain BANNED_DOMAINS = ['domain1.com', 'domain2.com'] def matches?(request) if BANNED_DOMAINS.include?(request.host) ## I WANT TO REDIRECT HERE WHEN THE CONDITION FAILS else return true end end end 回答1: Because Rails routes are executed sequentially, you can mimic conditional login in the following manner: # config

PSQLException: ERROR: null value in column violates not-null constraint

ぐ巨炮叔叔 提交于 2019-12-08 17:13:29
问题 I am using PostgreSQL 8.4.13 on x86_64-pc-linux-gnu on Debian 4.4.5-8, 64-bit. I have created the following table: CREATE TABLE users ( user_id serial PRIMARY KEY NOT NULL, name varchar(200), username varchar(150), password varchar(150), ); Then, using a Java application, I execute the following code: String insertTableSQL = "INSERT INTO USERS" + "(name, username, password) VALUES" + "(?,?,?)"; PreparedStatement preparedStatement = DBCon.prepareStatement(insertTableSQL); preparedStatement

PostgreSQL: is it possible to provide custom name for PRIMARY KEY or UNIQUE?

天大地大妈咪最大 提交于 2019-12-08 16:37:59
问题 When I write: CREATE TABLE accounts ( username varchar(64) PRIMARY KEY, I get primary key named: accounts_pkey Is it possible to assign my own custom name, for instance "accounts_primary_key"? Same story about UNIQUE . I couldn't find it in PostgreSQL documentation. Thanks in advance. 回答1: The trick is the CONSTRAINT part in the column_constraint section of CREATE TABLE . Example: > create table x(xx text constraint xxxx primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit

SQL remove autonamed constraints

喜欢而已 提交于 2019-12-08 15:36:53
问题 I have created a few constraints on my table with a script without specifying the constraint name. As a result, I ended up having constraints like FK__DOC_OBGS___kntr___54E63309 for example. Is it possible to drop that constraints without specifying the exact constraint name ? For example, something like this (which doesn't work) ALTER TABLE DOC_OBGS_10 DROP CONSTRAINT LIKE 'FK__DOC_OBGS___kntr%' The problem is that we have a lot of databases with this table and I need to remove all the

Adding programatically created views into scrollview vertically (Linear layout in iOS)

ε祈祈猫儿з 提交于 2019-12-08 15:16:30
I want to add programatically created UIViews into scrollView with auto layout constraints. Like vertical linear layout in Android. (In objective c not swift) I have scrollview inside view controller in storyboard. So basically i want to create and add several views in vertical layout with no spaces into that scrollview. And i want to set container size of the scroll view dynamically according to the view heights. Each view has label inside and each view needs to set its height dynamically according to text size. But probably i need to come to that later. for (int i=0; i<10; i++) { UIView

Constrained minimization in MATLAB

喜你入骨 提交于 2019-12-08 13:54:14
问题 I want to solve a constrained minimization problem and I am asking for some help on how to structure the code. I understand that fmincon is what I should use by playing with the argument @mycon but I am struggling in adapting it to my case. Any suggestion would be extremely appreciated. These are my files ( a and b are predefined parameters): f1.m function [y1, y2, y3]=f1(x1, x2, a) ... end f2.m function w1=f2(x1, x2, y2, y3, b) ... end Problem that I want to code: min y1 w.r.t x1 , x2 such

Typescript generic constraint for child classes

孤人 提交于 2019-12-08 13:26:33
Using Typescript 2.3.4. I'm trying to put a generic constraint on a method parameter, like so: public static FromFactType<T extends FactCore>() :T . FactCore is a base class which has three direct descendents: FactEvent, FactDuration, FactPlain . Each of those direct descendents has 15-20 separate children which add new properties. As an example, FactEvent has a child FactBirth , so FactBirth inherits indirectly from FactCore . However, when I try to pass an instance of FactBirth into my method, I get an error: Type BirthFact cannot be converted to type 'T' . The only way I've been able to

Finding the smallest solution set, if one exists (n multipliers)

流过昼夜 提交于 2019-12-08 13:23:44
问题 Note: This is the n-multipliers variation of this problem. Given a set A , consisting of decimal values between 0.0 and 1.0, find the set B , such that each b in B is a set consisting of decimal values between 0.0 and 1.0, such that for each a in A , there is a set of unique values where a is the product of a subset of elements in B . For example, given $ A = [0.125, 0.25, 0.5, 0.75, 0.9] A possible (but probably not smallest) solution for B is $ B = solve(A) $ print(B) [[0.25, 0.5, 0.75, 0.9

How to change textview height constraint within table view cell?

隐身守侯 提交于 2019-12-08 12:44:26
There's been a lot of questions about how to make dynamic cell height using Autolayout and TextView inside it. Here's the story I follow this article iOS dynamic table view cells with varying row height and Autolayout . In this case, we replace the 2nd label in the article with a TextView, with the same set of constraints The TextView does not have intrinsic content size as the Label. So we must use sizeThatFits and creating height constraint on the TextView, like this. This height constraint is an IBOutlet from the Nib ViewController.m - (CGFloat)tableView:(UITableView *)tableView

ScrollView with embedded StackView issue

夙愿已清 提交于 2019-12-08 10:44:45
问题 I have a scrollView with a stackView placed in it. The scrollView is constrained to the rootview . The stack view will show a xib view. The xib views are all different lengths. The xib views are labeled simpleVC0 and simpleVC1 . The length of the simpleVC0 is 2500 and the length of simpleVC1 is 1000. My problem is that when the xib views are presented in the stack view the length of the scrollView does not change to the length of the presented xib view. It is like the xib view is presented