Ember.js: How to find a model by any attribute in Ember.js

One of the common things people ask about Ember Data is how to find a single record by it's attribute. This is because the current revision (11) only offers three methods of fetching records App.User.find(1) // returns a single user record App.User.find({ username: "wycats" }) // returns a ManyArray App.User.findQuery({ username: "wycats" }) // same as the above If you want to search for a user by his username, you have two options

Read More →

Ember.js: render, control, partial, view, template

There are many ways one can DRY up templates when using Ember.js, it all depends on what you're trying to achieve. partial && template {% raw %}{{partial "foo"}}{% endraw %} will take a template foo.handlebars and insert it without changing anything, which is exactly the same as in Rails. There are no views created, no scope changes, it just inserts the template right there. {% raw %}{{template}}{% endraw %} isn't really meant to be used anymore, so use {% raw %}{{partial}}{% endraw %} instead.

Read More →

Ember.js: Router and Template Naming Convention

Ever since the change to resource and route a lot of people are confused about the meaning of the two and how they affect naming. Here's the difference: resource - a thing route - something to do with the thing Let's say we have a model App.Post and we want to show a list of posts and a new post form. There are many ways you can go about this, so let's start with the simplest.

Read More →

Ember.js: Router Request Lifecycle

Router is the core part of Ember. Every time we go to a new URL it means the route object is called with our params and stuff. These are the hooks sorted in order in which they are called enter (private) activate - executed when entering the route deserialize (private) model (formely deserialize) - takes the params and returns a model which is set to the route's currentModel serialize - used to generate dynamic segments in the URL from a model setupController - takes currentModel and sets it to the controller's content by default renderTemplate - takes current controller and what model returns and renders the template with an appropriate name deactivate - executed when exiting the route (called by exit internally) exit (private, requires call to this.

Read More →

Ember.js: State Manager and Friends - part 1

Since state management is such a huge part of Ember.js it desrves a dedicated article. I'm not going to explain the old router which used Ember.StateManager to do it's bidding. Those days are over and we should all be moving towards the v2 router (or v2.2 so to speak). Instead we're going to go deep into the Ember.StateManager. In the general concept, state manager is basically some object which manages states and the transitions between them, thus representing a finite state machine.

Read More →

Ember.js: Testing Ember.js - part 1

Ever since I saw the testing slides from EmberCamp I was thinking about testing. Up until now I've been using Capybara which is really really really slow. But @joliss mentioned this thing called Ember.testing which should automagically fix all of the async problems which make tests ugly, such as waiting for the application to initialize and finish routing. In its essence Ember.testing = true disables the automatic runloop, which gives you the control to manually schedule asynchronous operations to happen in a one-off runloop via Ember.

Read More →

Ember.js: Using Transactions in Ember Data - part 1

We talked about transactions in one of the previous articles (read it if you haven't already), but we didn't really touch on when to use them in real world. One of the most common use cases for me is when I just want to manage a single record while there are many changes happening on the page. Adding a record to a transaction is simple // say that we are in a controller store = this.

Read More →

PostgreSQL Basics by Example

Connecting to a database $ psql postgres # the default database $ psql database_name Connecting as a specific user $ psql postgres john $ psql -U john postgres Connecting to a host/port (by default psql uses a unix socket) $ psql -h localhost -p 5432 postgres You can also explicitly specify if you want to enter a password -W or not -w $ psql -w postgres $ psql -W postgres Password: Once you're inside psql you can control the database.

Read More →