Ember Server Side Form validation with Mirage

In this Ember.js example, I’ll show how to get ember-cli-mirage to return correct JSON-API response, so that Ember Data correctly processes Error message and makes it accessible inside the template.

This code was tested on Ember 2.6.0.

We have the following registration model:

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
  firstname: attr('string'),
  lastname: attr('string'),

There are three main elements that make this work: Controller that saves the data, Template that renders form and errors, and Mirage that mocks the response.

Controller’s save action is very basic, it calls save on the model and catches any errors:

import Ember from 'ember';

export default Ember.Controller.extend({
  actions: {
    save() {
      this.get('model').save().then((registration) => {
        // it's a mock, we don't do anything
      }).catch((adapterError) => {
        // we just need to catch error

Template displays form and any connected errors:

    <label>First name: {{input value=model.firstname}}</label>
    {{#each model.errors.firstname as |error|}}
      <span class="errors">{{error.message}}</span>
    <label>Last name:
      {{input value=model.lastname}}
    {{#each model.errors.lastname as |error|}}
      <span class="errors">{{error.message}}</span>
  <button {{action 'save'}}>Save</button>

Now we only need to setup Ember Mirage. We emulate two different states. If firstname is ‘John’, we let request come through, and in all other cases we display error.

import Response from 'ember-cli-mirage/response';

export default function() {

  this.namespace = '/api';

  this.post('registrations', function(schema, request) {
   let attrs = JSON.parse(request.requestBody).data.attributes;

   if ( attrs.firstname === 'John') {
     return {
       'id': 1,
       'firstname': 'John',
       'lastname': attrs.lastname
   } else {
     return new Response(422, {}, {
        "errors": [
            "source": { "pointer": "/data/attributes/firstname"},
            "detail": "Please enter John as name"

In the above example, it’s important that we return error code 422 (Unprocessable Entity), otherwise it will not be processed by JSONAPIAdapter as error.

Example repository

To make easier to see a complete and working example, I’ve also published a repository with complete code:

Is it worth recording videos at Conferences and Meetups?

We’re at the most busy point of organising WebCamp Ljubljana 2016. One of the questions we had to ask ourselves is – should we record the talks? It seemed that in previous years, did it because Kiberpipa and everyone else too. As organizers, we want to question decisions made in previous years. This is why we decided to investigate our decision to record the conference.

The effort required

We have 3 concurrent tracks. That means we need 3 semi-professional cameras with tripods, external mics and all the electricity. To get all of this together, somebody has to prepare and source the equipment. The on the conference day, 3 people are recording and you usually need 1 person extra as a support. Then after everything is over, it has to be edited and published. A few more days of work.

How did we do in previous years?

I looked through the stats for the videos. I didn’t know what to expect, but our most viewed video had 650+ views and the second one over 500. Then it’s slowly dropping off but a number of videos with 50+ or 100+ is still not too bad.

The real impact

One of the questions was – isn’t all this already taught through blogs, books and other conference recordings? And I believe that this just isn’t true. We’re still recording only a small amount of tech content. In addition to that, some speakers resonate well with us, while others we just can’t stand. Numbers show that people are watching and sharing the videos and that we help speakers have longer lasting impact.

So that made it really easy to decide to invest the effort on recording this years WebCamp again.

flickr photo shared by Thomas Hawk under a Creative Commons ( BY-NC ) license

What I learned building Open Education Week with Ember.js

I am lucky that at the Open Education Consortium, I can work with technology of my choosing. For Open Education Week site, I decided to experiment with Ember.js. It was my first production Ember app and I learned some valuable lessons.

Project background

Open Education Week site enables educators to submit their events and resources.  Visitors can then browse them. I used WordPress in previous years, and it worked fine to a point. It didn’t feel right when l I wanted to create more complex browsing interfaces.

Example of that would be: Show me all resources for colleges, that are in Spanish and have the following keywords in it. WordPress can do it, but it requires a lot of different taxonomies and custom queries.

I decided to build a thin Django API layer on top of existing data.

I tried using WP REST API, but it was hard to adopt. If I wanted to do more complex lookups, I still had to write complex WP_Query lookups. So that still wouldn’t help me on server side.

Good things about developing the site with Ember.js

Tooling is great

OEW is an Ember 2.3 application, written with ember-cli. This meant that I didn’t have to fight with grunt/gulp/etc. to get it to work. It just feels right, and it gives you things like real time reloading of CSS.

Components make things easy

It’s easy to make new components in Ember, that almost behave as Web Components. One example of that is my custom OEmbed component. I could reuse both in grid view and inside interactive map popup. (Demo)

Site feels fast

Once the page loads, the only requests you have to make are to the API. My other WordPress sites load fast, but requre refresh for every click. Single page app is fast.


Community of people that hang out on Slack and IRC is incredible and helpful. I just wished that it would also extend to discussion forums. Real time nature of Slack and IRC just don’t make it easy to Google previous discussions on the same topic.

Not so good things

Site is slower to load

Current size is 400kb of gzipped JavaScript assets. Until it loads, you only get a blank screen. I didn’t find how to make it display some sort of initial loading indicator.

My final Javascript size is about 2x the size of vanilla Ember.js with Ember data. It would be good to have tools that would tell me which addon is taking the rest of the space.

Redirects and prerender.io

People rename website URLs all the time. This means that my API, has to keep history of all slug renames. The problem is then – how to communicate it to Google? Google parses JS apps, but doesn’t follow redirects.

I’m currently running preprender.io to solve some of these problems. It works, but it requires extra work via meta headers.

Outdated recipes

As far as I understand, ember-data assumes that I will want to query objects by their ID. If I want to retrieve them by slug, I have to make a query and then return first item of matching results. This works, but it means that records don’t get retrieved from cache.

That is just one approach, but others did’t seem much better. When I Googled: “Ember.js query by slug”, I got a lot of different threads and discussions with varying approaches. The problem is that a lot of them are from 2013. How do I know if this is still the right approach in 2016?

It’s still early in addon ecosystem

When `ember install [addon-name]` just works, it feels magical. The problem I had is that a lot addons at this point assume good knowledge of Ember. I wish they would bundle demo applications and have more documentation. It reminds me a lot about Django’s ecosystem about 6 years ago. Then we got Read the docs and more mature plugins and things go a lot easier.

Is this site ambitious enough?

Ember’s tagline is: “A framework for creating ambitious web applications”.  The ambitious part is often quoted, when people want to use Ember.js only in part. It’s rarely explained what ambitious means.


Fastboot will fix most of my problems, but it’s still a few months away. The rest of my problems should go away as the community grows.

Would I build this site again with Ember.js? I think I would, because it gives me a much better foundation than a WordPress theme.

We need more mentors in our communities

Meritocracy is now a bad word. It’s increasingly used to describe communities that are built around outspoken individuals. They often don’t have clear rules and code of conduct.

Alternative to that, is mentorship or apprenticeship driven community. In this model, new members are given clear roles and are presented with the expectation and rules. They are also assigned a mentor that makes it their priority for them to succeed.

This model doesn’t necessary clash with the idea of meritocracy, but it makes it much less likely. In order to make on-boarding new members efficient, it  requires that these processes are written down. This removes a lot of power from individual members, as they can’t arbitrarily decide on what they want from new members.

I believe that such model also allows for greater diversity inside the group. Removing individuals’ discretion forces community to make it easier for more diverse group of members to participate.

Code of Conduct

I think that having a Code of Conduct is a basic building block of such a community. It doesn’t mean it’s welcoming or healthy, but it greatly increases the chances when coupled with clear on-boarding path.

Further Work

15 years ago we got the Joel Test. It presents 12 questions to ask your prospective employer. Since it came, a lot of these are given and things improved a lot.

I think we could benefit from having a similar test for online and offline communities. I sure don’t want to waste any more time with larger communities without CoC and without designed onboarding process.

3 things I learned at  Creative Corner in London

Last week I gave a talk at Creative Corner in London. Most event attendees were in the creative industries: design and music.
Listening to talks of Simon and Patrick, I learned that our experiences are not so different.

1. Coding process is not much different from creating Music or Designing a book

They all need their own time and focus. We are all distracted by external stimuli. That’s why it’s important that carve out that piece of the day, when create our most important work. Paraphrasing Patrick: “If you’re creating music, that’s your work. Don’t spend all your time, creating marketing content on social media.”

2. We all want to push the boundaries of our work

Simon shared promising designs, that got rejected by his clients. They ended up delivering much more bland and safe options. This is something I see often, when I explain the potential of web sites to my clients. Sometimes it works, but most often they don’t feel like innovating.

3. Our own work matters the most

At the end of the day, we’re most proud of our own work. The one where we could decided that safe, is not an option. It’s also often the case, that this is one of our best work that we end up showing for years to come. But the only way we can do it, is if we ruthlessly make time for it.

I really enjoyed the event and discussions afterwards. Make sure you attend next month!