Saturday, 15 January 2011

ember.js - emberjs + rails, how to specify the route and post a request to rails server -


How to post a request for rail server when click on the 'check' button

railroad

Rail sentence controller
  resources: find members to find: "Lang-RB CutePrint-Override">  Class SentencesController & lt; ApplicationController def probe json: end of false end   

emberjs route
  App.Router.map -> ; @ Source "sentence", - & gt; @ Source "sentence", path: ": sentence_id", - & gt; @ Root "check"   

emberjs template
  & lt; Script type = "text / x-handlebars" id = "sentence" & gt; & Lt; Button {{Action 'check'}} class = 'btn' & gt; Check & lt; / Button & gt; & Lt; / Script & gt;    

I think what you are trying to do, go against the conference Used to be. How should this happen, it is the assumption that you are just updating the 'check' variable on your model (make me correct if I am wrong).

Amber Side:

Router:

  app.rotter.map (function () {this.resource ('sentence', function ( ) {This.resource ('sentence', {path: ': sentence_id'});});});   

Administrator

  app.stentance controller = amber.object controller.edid ({check: function () {var sentence = this.get ('model '); Sentence. Set (' check ', true), sentence.get (' store '). Commit ();}});   

Template:

  & lt; Script type = "text / x-handlebars" id = "sentence" & gt; & Lt; Button {{action 'check' = "click"}} class = 'btn' & gt; Check & lt; / Button & gt; & Lt; / Script & gt;   

Then on the rim edge, you can get rid of the operation of the routes and the controller and just use the default endpoints (in this case when you work from the amber app By using Sentence # Update ( /sentences/:id/update.json ), this will change your Rail App.

No comments:

Post a Comment