Three ways you can bend the ransack gem to your liking

In the world's best yoga studio software for independent yoga studios, we have a page which lists all people in your studio. It's super basic: it only shows their name and role at the studio along with some actions you can take i.e. edit, delete. We haven't improved it much along the way.

I wanted to change that. TULA, in its essence, is a yoga centric CRM + billing system. Armed with inspiration from Intercom and their brilliant list of people, I set out to improve our people page.

We've had requests from our customers like "show me all the students who haven't been to class since X date" and "show me all the students who have joined the studio since Y date". These are great questions to ask and TULA should give you the answers. It's as simple as that.

To give them this, I did some investigation and found a great gem called ransack (if you haven't already, check out the ransack GitHub page). I quickly became satisfied with ransack as the basis of this new page. However, there were a few things I was constantly fighting with.

Ransackers derived from column aliases

This frustrated me for some time. I had a query like this:

I wanted to use their role, last attendance date, last purchase date, and join date as sortable columns in the table. However, it wasn't working out of the box until I realized I could simply pass an Arel node (thanks to this GitHub issue) of the column alias to a ransacker.

Default sort order

You can also use ransack to set a default sort order for when your users first visit the page.

Nulls last with ransackers

When you start sorting by column, you'll quickly notice null values getting in your way of the important data. For example, if you're sorting by the last time a user has made a purchase, you'll most likely want to see an order like this: about an hour ago, three hours ago, one week ago, etc. You wouldn't want to see an order like this: never, never, never, never, ... , about an hour ago, etc. The important data is getting buried by the nulls.

Ransack doesn't support this by default. However, there's a workaround (read more about how to add nulls last to ransack).

The workaround is great; however, it doesn't immediately work when you're using ransackers which return an instance of `Arel::Nodes::InfixOperation` or similar. You'll see a generated query similar to the following:

Obviously, this isn't valid SQL. This is actually due to the `full_name` ransacker defined above and in this case, the default sort order set to `full_name`. However, `Arel::Nodes::InfixOperation` responds to `to_sql`, so you can test for this case and transform it into valid SQL for the query. The code below will show you how:

Ransack is powerful, and we're just scratching the surface of its power. If you think I missed anything important, just mention me on Twitter or add a comment below.

Poker, business, and the optimal decision

When you reach a certain level of any topic, you realize how deep the rabbit hole goes. That's why the term professional, when used the right way, is so prestigious. When it comes to poker, the same is true. It's a deep game and most variants of pokers haven't achieved GTO (game theory optimal).

Sure, there's a generally agreed upon way to play most games of poker. Most often, aggression is the key to victory. But, most people think it's all about the numbers or the cards you're dealt; however, it couldn't be further from the truth.

Variables you must consider:

  • The number of chips you have (money in the bank)
  • The number of people still in the hand (people still in the game)
  • The person on your left
  • Your opponent's aggression
  • Your opponent's lack of aggression (most incumbents)
  • The number of chips in the pot
  • The number of chips on the table (the size of the market)
  • The person on your right
  • Your opponent's range of cards (their people)
  • Your cards (your people)
  • The list goes on and on...

You use all of these variables to make a decision. You should always ask yourself: What's the optimal decision? If you don't make the optimal decision, you might get lucky and still win. However, you're definitely more likely to lose.

If you do make the optimal decision, you're slightly more likely to win - but you could still lose. That's the catch.

Just like poker, business follows along. You can make all the right decisions, and you can still get unlucky. On the other hand, you can make a bad decision with luck on your side.

The best we can do is make optimal decisions. The optimal decision is the one which gives us the greatest chance to win.

And like business, poker is a long-term game. Over the short-term, any victory or loss is almost certainly due to a high amount of luck (variance). However, when you stretch your decisions over many years, the person making the most optimal decisions reduces the amount of luck effecting his results.

An example of this in business is the moat. Over many years, a company makes optimal decisions, creating many different mechanisms by which they keep their competitive advantage. Compare this to the company just starting out with one product. They need some luck to stay alive.

Even though we can try, it's impossible to always find the optimal decision. Your opponent may be great at altering his play to trick you into a less than optimal decision.

Sometimes the optimal decision is to just go with it. The same is true for business. Sometimes you just don't know what to do. That's ok. Make the decision and be ok with it. The important part is to reflect and study that decision. Knowing what you know after the fact, was it the optimal decision? If yes, you were lucky. If no, figure out why. Armed with that knowledge, you should be able to move toward more optimal decisions in the future.

Product Market Dance

I've never really liked the phrase 'product-market-fit'. It's never felt right to me, in the same way the phrase 'passive income' doesn't feel right. They both imply that that you get to a point of stillness at which everything stops and you're 'done'.

But that's not how the economy works, and it's certainly not how technology companies and software work. 

Today's product/market fit might be tomorrow's myspace. The market is constantly shifting and evolving, and so too are the products that serve them. It's wise to remain focused, but not at the expense of missing an entire market shift that kills your company. 

Markets are alive, we have new devices and new pieces of hardware at our disposal and with more coming. Not only this, people's expectations change. Like the changing beat of a song as it reaches a climax and comes back down again, so too does the market, and your customers fluctuate.

Today's Minimum Viable Product is tomorrow's starting point. Interestingly, today's failure can be tomorrow's success too, because there is such a thing as being too early.

Here's another secret: within markets there are different songs playing. Our biggest competitor to Tula is a half-a-billion dollar company in what they call the 'health, beauty and wellness' category.

That's one song I suppose. Another? Independent Yoga Studios.

There are many songs playing in every market. 

There's no such thing as product/market fit unless you're talking about a short time horizon.

For anything longer, it's a dance.


Venture Ethics

Fred Wilson, the well known technology investor and all around inspirational guy, wrote a blog post yesterday titled Ethics and Morals. In it, he wrote about a Venture Capitalist who turned down an investment opportunity with a company, and shortly thereafter provided an angel round for his son in a competing business.

There are more details, and the entire post is worth a read.

But one of the things with the post is he didn’t actually name the name of this venture capitalist. And that’s fine I suppose, but it prompted me to ask this:

I asked the question because this isn't the first time I've heard an investor call another investor out in public, without actually calling them out.

I recall Dave McClure calling out investors for blocking early stage investors from participating in follow on rounds (another thing Fred Wilson's written well about here), for example. 

There too - no names.

What I'd like to argue is that these public announcements, in and of themselves are problematic for entrepreneurs, are counterproductive to the investor's goals of attracting the best entrepreneurial talent, and underscore the very reason why people like me don't trust investors. 

To be clear, I don't mean this in the "I don't trust them personally" kind of way. My guess is they're both probably pretty awesome, their firms are the best in the biz, etc. I think they're the 'good guys' is my point. 

And also, Fred does yoga!

What I mean is, I don't trust their industry, and these non-outing outings help explain why.

To be good it seems to me investors have to simultaneously compete with each other, and collaborate with each other. This is so much grey for someone like me I can barely take it. And I don't mean this in a positive way about myself, I just mean it just sounds so damn hard.

But all I see when I read these non-outing outings is the fact that it's more important to protect the investor to investor relationship than it is to warn entrepreneurs about the shady investor.

And look, I get it.

I actually changed my mind in the process of writing this post about whether it was 'right' or 'wrong' not to mention names. We've had numerous investors reach out to us about Tula, while proudly including the fact that they invest in our main competitors. And all I can think to myself is: someone who wants to invest in us might be reaching out to our newest competitor in three years?

But I don't want to call these people out either.

What I initially thought was irritation that these investors weren't naming names is actually touching something deeper. How these dots connect for me now, is they highlight very clearly that there is an investment world, and there is an entrepreneurial world and in between there is a chasm of trust.

It makes me sad when investors I like and follow and admire are contributing to making this chasm larger instead of smaller, especially when they are each usually doing the latter.

But the fact of the matter is that they both have had a situation where they've fired shots across the bow at other investors, using a dog whistle instead of a bull horn, while on just about every other industry related topic they are talking openly and in public.

I think it's great that we're talking about ethics, but let's be clear, these are venture ethics, which still leave some open questions for the entrepreneur.


We don't want to be anonymous, we want to be known for the first time again


I think sometimes about what kind of effect the internet will have on us, and in particular our children, as it becomes harder and harder to move away from our pasts.

I don't mean this in a 'running away from our past' dramatic kind of way. I mean it more in the spirit of, when we graduate from grade school, and then high school, then college and maybe a job or two, we end up sort of refining ourselves along the way.

When you go to university, it's sort of nice to meet someone who didn't know you when you had your most embarrassing high-school moment. When you take that first Director level job, it can be welcome if your new reports haven't seen you pass out at the Christmas party because you can't handle your whiskey.

Not that I would know anything about that.

The idea is that as we move through life, as we naturally transition from one period to the next, we bring some of ourselves forward with us, and we leave other parts behind. We learn and grow and mature and hopefully, who we are at 40 is a better version of who we are when we're 20. 

What happens though when it becomes hard, or impossible, to leave our more unrefined selves behind? 

There's a concept in psychology called the "Looking glass self" that says our self perception is based at least in part on how others perceive us. This notion is so powerful that people can have important breakthroughs with issues such as addiction, simply by seeing a new person in their lives perceiving the in a positive way.

If you think about it, this makes sense sort of intuitively. If you were suddenly treated like a movie star, allowed into all the greatest clubs for free, fashion designers sending you clothes for nothing and you had people hounding you for autographs - you'd probably have at least some shift in your sense of self. Likewise, if everyone started being very mean to you, telling you were worthless over and over again, this too would have an obvious impact.

But what happens when people's perception of us is based on 10 years of a Facebook timeline and 8 years of a web log? Is this simply our reputation, something that everyone in every generation before us has worked with?

Or does this always available history have an influence on how we're perceived? And if so, then doesn't this mean we'll perceive our own selves differently than we otherwise might have? And what happens when we're comparing our real world selves to other people's Instagram filters?

What is this doing to our perception of self?

There was a trend in 2014 with anonymous apps such as Secret and Whisper seeing massive user growth, and for many there's a strong belief that many people have a craving for an anonymous presence on the internet. But I don't think anonymity is the thing we want. Anonymity is the thing we want so we can get the actual thing we want - which is to be know by someone else for the first time again. 

Anonymity is just a pre-requisite for that.

The always on, always searchable, history always available nature of the internet is amazing and important and a regular thrill. But as with everything, there are trade-offs, and the internet has made it significantly more difficult to be known for the first time again.

I've become of the mind that anonymous apps aren't trying help us be evil or wicked or dangerous, or even anonymous, though surely there are some that use it for that.  Instead, I think they're trying to help us scratch the oldest of itches: to provide a way for new people to perceive us, so that we can have more inputs so as to build our own self-perception. A few of us want to be anonymous, but most of us want to be known.

If we can be know by someone for the fist time again, then even better.