Reputation: 58
I'm a beginner coding with Ruby on Rails and I make games in my spare time. I've built a basic website using Ruby on Rails to host/display the games I've worked on. I find it fun to learn new languages by building games, and I'd like to play around with a text-based RPG to explore what Ruby on Rails can do. I want to host it on my site but I don't want the MVC structure of the game to be mixed with the structure of the website. What would be the best way to keep them separated? I've been reading about the engine feature of ruby on rails. Would this be a viable way of accomplishing this? Otherwise, would it be possible to build it as a separate rails application and embed it into the website?
Sorry for the long block. Hope it makes sense, and thank you for your help.
Upvotes: 3
Views: 715
Reputation: 76774
You could make an engine for sure.
Engines are self-contained applications.
Especially if you use the isolate_namespace
directive, the engine will have very little baring on the "main" app. You can reference it with main_app
, but ultimately, it will be self-contained:
#lib/game/game.rb
module Game
class Engine < ::Rails::Engine
isolate_namespace Game #-> url.com/game
end
end
This acts in almost the same way as a "namespace" does in your routes file -- puts your entire game code inside a module:
# lib/game/app/controllers/game/application_controller.rb
class Game::ApplicationController < ActionController::Base
x
end
A good example of what you could do would be as follows...
#app/models/game.rb
class Game < ActiveRecord::Base
#schema id | name | created_at | updated_at
has_many :players
end
#app/models/player.rb
class Player < ActiveRecord::Base
belongs_to :game
end
The above would allow you to manage the "players" on your site, to which you'd be able to then update the scores on the games themselves.
I could give you more information but need to know if this is what you were thinking of first. If you let me know in the comments, I'll be able to update appropriately.
Upvotes: 2