Search code examples
ruby-on-railsajaxember.jsember-data

Custom route for record.save() in ember


In ember , I have a model called "Post" . If i perform

 record.save() 

on creating a post , by default it posts to my /post url in Rails(backend). This works in my case. But for future uses, how do i specify a custom route? Let's say I want to post this model to my backend to a route called

"/post/save" 

How do i make record.save() in ember to go to this route?


Solution

  • Adapters in ember manage how a model communicates with remote data. If you need to go outside of ember convention, you can create a custom adapter for your model that can point actions to different places.

    ember generate adapter model-name
    

    In your case, you want to call /post/save instead of /post when you create a post. You would overload the method urlForCreateRecord:

    urlForCreateRecord(modelName, snapshot) {
      return '/post/save';
    }
    

    Each url for an action (create, update, new, find, query) can be adjusted to fit your backend.