ルーターにオブジェクト ルートがあり (標準の REST バックエンドで ember-data を使用) connectOutlets
、オブジェクトを単純に逆シリアル化してロードし、アウトレットに接続します。
# inside router
action: Ember.Route.extend
route: 'object/:object_id'
connectOutlets: (router, object) ->
unless object.get('isLoaded') # What goes here to tell if the object wasn't found?
#
# handle this case (e.g., redirect)
#
else # otherwise proceed as normal
router.get('applicationController').connectOutlet('object', object)
に移動するlocalhost/#object/object_that_doesnt_exist
と、ルーターは URL をデシリアライズし、オブジェクトのロードを試み (サーバー ログは localhost/objects/object_that_doesnt_exist に対する HTTP GET 要求を示します)、404 を取得し、代わりに id が に設定された新しいオブジェクトを作成しますobject_that_doesnt_exist
。
これを検出してケースを処理したい。現在、isLoaded
既存のモデルと存在しないモデルを区別するプロパティを確認していますが、これが最善の方法かどうかはわかりません。
理想的には、Rails のnew_record?
.