ruby on rails - How should I be updating data with AJAX? -
i making rails mvc style application.
when loading pages, controller gets data model , forwards view , view renders itself.
however, wondering appropriate way interact between javascript , database.
say user playing game , has bunch of clues on screen. clicking clue move clue box , needs update userclues model add clue.
the user needs able remove clues clue gets removed etc...
this needs happen via ajax.
i wondering appropriate approach is.
say got page /investigation loaded page using investigationcontroller.
should investigationcontroller 1 calling model add/remove clues, or should sort of data controller it.
for example:
/investigation/addclue or controller
/user/clues/add the reason asking have lot of data on pages created/added/modified , wondering if routes/controllers should separate data manipulation , pages, or if should have controller each page , manages user can on page (like add / remove clues , cluebox)
thanks
ideally want have separate controller each resource. though current view in context of investigations, controller, dealing clues should have own resource. otherwise things can complex. if clues investigation specific, can scope them under investigation url.
resources :investigations resources :clues end this give /investigations/1/clues/1, maybe not necessary, , avoid nesting unless required.
the controller can respond in correct format. in case rails ujs provides tools need. can render create.js.erb or destroy.js.erb templates handle user actions. templates have required javascript , dynamic code update screen state.
Comments
Post a Comment