Friday, 15 June 2012

Saving Rails model as JSON -



Saving Rails model as JSON -

this seems question have been asked, couldn't find quite looking for, i'll go ahead , ask.

i'm trying utilize angular.js create instant search function on site. want users able search through posts (by title , content, ideally) instantaneously, after hearing angular's ability this, gave shot.

i have going on in posts.js.coffee file:

@postlistctrl = ($scope, $http) -> $http.get("posts.json").success (data) -> $scope.posts = info

and going on in json doc references (just create sure working -- is).

data = [ name: "blog ex" content: "this illustration post." , name: "test posting" content: "a different ex post" , name: "test3" content: "this has unusual, unique vocabulary." ]

now have left rails save object (with name/content attributes) in above json file each time new post created, search runs through meaningful data. i'm new rails/json/computer stuff , don't have clue how this. i'm guessing it's in posts controller, maybe in 1 of respond_to blocks, if point me right way this, i'd appreciate it.

if want instant search, or autocomplete functionality, should not utilize angular.js or other js mvc frameworks. instead, consider using jquery @charliefl suggested, it's easy. simple ajax phone call it.

js mvc frameworks heavy, , need design architecture bottom suit them. not worthy such single functionality.

to create function work in jquery, basically:

listen event on search box, typing 1 or more characters catch characters , utilize jquery ajax send post request method in postscontroller in rails, "search" make method respond json. update dom according server response.

ruby-on-rails ruby-on-rails-3 json controller angularjs

No comments:

Post a Comment