voltrb - Use ruby classes in Volt Framework -
i wondering best way include ruby classes in volt framework. want use socket class find ip address of visitor of site. want use in controller, putting:
require 'socket'
at top of file not work. suggestions?
well, don't think can use socket class on client-side since volt uses opalrb run ruby on client, , unfortunately don't think opal can support socket class since that's kind of hard in browser. can, however, run code on server side , pass desired results on client. can using volt's tasks. can create them so:
require 'socket' class sockettask < volt::task def use_sockets # thing sockets here... end end
and can use them elsewhere, e.g., in controller this:
class controller < volt::modelcontroller def some_action sockettask.use_sockets # can use #then method of returned promise result of call. # can use #fail method on promise thrown errors. # following can run code on client. sockettask.use_sockets.then |result| alert result end.fail |error| puts error end end end
there's screencast rick carlino volt tasks here.
Comments
Post a Comment