Check if record exists from controller in Rails

Why your code does not work? The where method returns an ActiveRecord::Relation object (acts like an array which contains the results of the where), it can be empty but it will never be nil. Business.where(id: -1) #=> returns an empty ActiveRecord::Relation ( similar to an array ) Business.where(id: -1).nil? # ( similar to == nil? … Read more

how to prevent “directory already exists error” in a makefile when using mkdir

Looking at the official make documentation, here is a good way to do it: OBJDIR := objdir OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o) $(OBJDIR)/%.o : %.c $(COMPILE.c) $(OUTPUT_OPTION) $< all: $(OBJS) $(OBJS): | $(OBJDIR) $(OBJDIR): mkdir -p $(OBJDIR) You should see here the usage of the | pipe operator, defining an order only prerequisite. Meaning … Read more

is_file or file_exists in PHP

is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory. So it would depend entirely on your needs. If you want to know specifically if it’s a file or not, use is_file(). Otherwise, use file_exists().

MongoDB: How to query for records where field is null or not set?

If the sent_at field is not there when its not set then: db.emails.count({sent_at: {$exists: false}}) If it’s there and null, or not there at all: db.emails.count({sent_at: null}) If it’s there and null: db.emails.count({sent_at: { $type: 10 }}) The Query for Null or Missing Fields section of the MongoDB manual describes how to query for null … Read more

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS

You can’t return two (or multiple) columns in your subquery to do the comparison in the WHERE A_ID IN (subquery) clause – which column is it supposed to compare A_ID to? Your subquery must only return the one column needed for the comparison to the column on the other side of the IN. So the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)