The situation is like this, I have a rails REST controller that handles location resources (location, description, latitude, longitude), that's actually working fine and serves correct JSON responses.
Then I setup a batman app inside my rails application, scaffolded a Location resource, with controller, views, and model, but in some places of my pages the location data is not being displayed with data-bind.
Here is what i have so far:
app/assets/batman/models/location.js.coffee
class Sightseer.Location extends Batman.Model
@resourceName: 'locations'
@storageKey: 'locations'
@persist Batman.RailsStorage
@validate "description", { presence: true }
@validate "location", { presence: true }
# Use @encode to tell batman.js which properties Rails will send back with its JSON.
# @encode 'name'
@encode "description", "latitude", "location", "longitude"
@encodeTimestamps()
app/assets/batman/controllers/locations_controller.js.coffee
class Sightseer.LocationsController extends Sightseer.ApplicationController
routingKey: 'locations'
@beforeAction 'findLocation', only: ['show', 'edit']
index: (params) ->
@set('locations', Sightseer.Location.get('all'))
show: (params) ->
edit: (params) ->
new: (params) ->
@set('location', new Sightseer.Location)
create: (params) ->
@location.save (errors, record) =>
if errors
throw errors unless errors instanceof Batman.ErrorsSet
else
@redirect record
update: (params) ->
@location.save (errors, record) =>
if errors
throw errors unless errors instanceof Batman.ErrorsSet
else
@redirect record
destroy: (node, event, context) ->
if context.get('location')
location = context.get('location')
else
location = @location
location.destroy (errors) =>
if errors
throw errors unless errors instanceof Batman.ErrorsSet
else
@redirect '/locations'
findLocation: (params) ->
Sightseer.Location.find params.id, (error, record) =>
@set 'location', record
apps/assets/batman/html/locations/show.html (The page with the issue)
<h1 data-bind="location.id"></h1>
<h1 data-bind="location.location"></h1>
<p data-bind="location.description"></p>>
<a data-route="routes.locations[location].edit">Edit</a> |
<a data-event-click="destroy">Destroy</a>
Whenever I hit /locations/2
I get from Rails the followin json:
{"id":2,"author_id":null,"description":"test description","latitude":40.7143528,"location":"test location 2","longitude":-74.0059731,"created_at":"2014-10-09T02:26:31.352Z","updated_at":"2014-10-09T02:26:31.352Z"}
I can see in the show.html page that the "id" attribute is bound, but the "location" and "description" are not, the attributes are showing fine in index.html page.
Is there something I am missing? Is anything wrong in the controller and / or the view?
Thanks
Pablo