Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8996357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:39+00:00 2026-06-15T23:44:39+00:00

My project is to make a website with html5 games, in Rails. I have

  • 0

My project is to make a website with html5 games, in Rails.

I have a controller called games_controller, and I would like to match /games/name-of-my-game with each html5 games. I created a route, matched with a games_controller function, but here is my problem:

I want everything to be “plug-and-play” for my html5 games, I mean develop them out-of-Rails, then just copy/paste it inside my app and everything works fine (references to images,.js files and all). But I also want my game’s view to be inside my application layout. Here is what I tried :

  • Put it in /public directory, and in my games_controller’s show method do render "/public/path_to_my_game". This breaks all references like <script type="text/javascript" src="some_script.js"></script>, cause the url isn’t */path_to_my_game* but /games/name-of-my-game.

  • Put it in /public directory, but with a redirect_to in my show method instead render. The references are not broken, but the layout is gone (I may be wrong, but layouts are stuck with controllers, not static files).

  • Put it in app/views/games but this seemed ugly so I quickly stopped :).

Does anyone have an idea ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:44:40+00:00Added an answer on June 15, 2026 at 11:44 pm

    If you have something like

    # config/routes.rb
    match '/games/:game' => 'games_controller#show'
    
    # app/controllers/games_controller.rb
    def show
      @game = params[:game]
    end
    

    All you really have to do in your layout file is

    <%= javascript_include_tag @game %>
    

    This means you will have a app/assets/javascripts/<game>.js file for each game you have. It will be responsible for booting each game.

    Obviously, you will want to take precaution to validate that params[:game] is a valid game.


    Alternatively, you could create a content section in your layout file

    <html>
      <head>
        <%= yield :game %>
      </head>
      <!-- rest of layout ... -->
    

    Then serve the appropriate view with your GamesController

    # app/controllers/games_controller.rb
    def show
      @game = params[:game]
      render "games/#{@game}"
    rescue ActionView::MissingTemplate
      redirect_to root_path, :alert => "invalid game id"
    end
    

    Then in your game views, you will require all necessary files for each game. For example, a user visits /games/pacman

    # app/views/games/pacman.html.erb
    <% content_for :game do %>
      <%= javascript_include_tag 'pacman/foobar' %>
      <%= javascript_include_tag 'pacman/start' %>
      <%= stylesheet_link_tag 'pacman/styles' %>
    <% end %>
    

    Another example, user visits /games/time_pilot

    # app/views/games/pacman.html.erb
    <% content_for :game do %>
      <%= javascript_include_tag 'time_pilot/init' %>
      <%= stylesheet_link_tag 'time_pilot/base' %>
      <%= stylesheet_link_tag 'time_pilot/retro' %>
    <% end %>
    

    Because I’m sure each game is going to have a different amount of dependencies and they will all be initialized differently, you can build the view for each game accordingly and serve up whatever assets are relevant to each game.


    Fore more help with with layouts and rendering, see the rails guide: Layouts and Rendering in Rails

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a website where I can present some project of
I have a C++ small project using GNU Make. I'd like to be able
I am working on a project (website) where I need to make a feature
I am making a small website as my first project. I have finalized to
I am teaching my friend how to make websites. I would like to keep
I have a project where a user will go to username.website.com. Once the page
My question is about jquery. Recently I have built a website as a project
I have a presentation tomorrow, and while I was trying to project my website
I am using Visual Studio 2010 for an MVC website project. I have an
I am trying to make a website with a video background using HTML5's video

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.