0

Is it possible to handle databases in Ruby as you would in a Rails website?

I'm writing a Websocket game server in pure Ruby, and it would be easier if I could just handle data in Ruby as you would in rails: User.find_by(:email) or User.save instead of using SQL statements. Is this possible, or better yet, could I write a websocket SERVER in Rails? I'm using Postgres and Ruby 2.0.0. I'm also writing a Rails application using Rails 4.

1 Answer 1

2

Is it possible to handle databases in Ruby as you would in a Rails website?

Yes, activerecord is a gem and can be used outside of Rails.

See this question/answer: https://stackoverflow.com/a/1643938/382982

You could also use DataMapper, Sequel, etc.

Sign up to request clarification or add additional context in comments.

4 Comments

+1. One other thing: canI share ActiveUser objects between my website and server? For example, I create a User object from ActiveRecord on my Rails site, is there a way to reference that same object in my server, or do I have to hard code it to fit with my database?
In that case, why not have your non-Rails site act as an API client of your Rails site?
I'm not sure I understand; by non-Rails site, you mean my server? Would that just involve having my ActiveRecord objects live with my websocket server instead of the website, then use Rails to require those objects? Sorry for noobish question :/
Yes - I meant your server. I've never worked with WebSockets and Rails, but I'd imagine you'd send your objects over the socket as JSON, make whatever changes you nedd to and then broadcast them back to the server, who'd look for an ID and update that record accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.