Ruby on rails embed game - ruby

I am using rails 3.2.12 version.
I want to embed HTML5 game in my static web page (game.html.erb).
I am confuse about what will be the src of Iframe tag?
I am using
<pre>
iframe src="index.html" height="460" width="500"
</pre>
in game.html.erb page
but error occurs
NO ROUTE MATCHES GET "/static_pages/index.html"
I have put game file index.html in same folder as game.html.erb.
what is issue?

If the html is static then just move the html file into the '/public' folder of your rails app and change the src for the iframe to be "/index.html"
If you don't want to put it into the public folder, you'll need to either add an action to the controller that your game.html.erb is rendered from or create a separate controller for the static html.
Based on what your question states though, I would put it into the public folder as it is just static html and wouldn't require a controller.
The problem with the setup you have is that your index.html file is just a static file, where the view folder that contains game.html.erb relates to a controller and is rendered from an action in the controller. Static files don't get rendered from that folder. The public folder contains static files and folders that you want on the root of your site (except for javascript, images and css which go in the asset pipeline).

Related

css file not found - asp.net core web application

I have created an asp.net core web application (I started with the Empty option) and I am building it step by step. It seems my css file is not being read or found though.
When I launch the application I can see that my html page does not look as it should be and when I use the developer tools in edge under the console there is an HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - http://localhost:8888/css/site.css error which would indicate my css file is indeed not being read or found.
Now, my css file is under a folder called "css" which is in the root of the project. When I say root I mean that I have just created a folder called css and the path is the same of Program.cs or Startup.cs. There is no wwwroot in my project (seems that asp.net core 2.2 has removed it by default?) and the css folder is not there. As follows the code from my html page, I have tried to add the ~ before the "/css" but still nothing.
<head>
<link href="/css/site.css" rel="stylesheet" />
</head>
If you would like that static files to be served outside of the web root (for example in a folder named MyStaticFiles) and it has the structure like
-YourProject
--MyStaticFiles
---css
----site.css
--Program.cs
--Startup.cs
You could use app.UseStaticFiles, refer to Serve files outside of web root
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
RequestPath = "/StaticFiles"
});
}
Then you could get the css from http://localhost:8888/StaticFiles/css/site.css
or <link rel="stylesheet" href="~/StaticFiles/css/site.css" />
It is happening because environment webroot is different than the css folder is currently in. You have to change the webroot or move your css folder to current webroot.
Normally the wwwroot folder is set at environment webroot

Laravel 5 - Loading Public JS / CSS / HTML Files From Custom Folder?

Laravel serves client side (HTML, CSS, JS) files from the /public folder by default. I am currently transitioning a Blade based front-end to an Angular based one. As a result, I am mixing Blade templating with Angular templating. I am using Blade layouts to generate a navbar, footer, and other common views while I transition the body content of my pages to Angular.
I have a folder constructed just for storing Angular files. My current app structure looks something like this:
-MyApplication
-angular
-app
-bin
-bootstrap
-config
-database
....
Is there anyway for Laravel to load my assets - stored in the /angular folder? I want to keep all my Angular files in one place, in standard Angular structure, as opposed to spreading them out and placing them in the /public Laravel folder.
You can try to create a symbolic link inside the public directory to your intended angular directory. Open your terminal and create a symbolic link like so:
ln -sfv ~/path/to/MyApplication/angular ~/path/to/MyApplication/public/angular
Don't forget to update the ~/path/to/MyApplication to your actual Laravel directory. Now you may refer to the javascript file inside the angular directory like this on your blade template:
<script src="{{ asset('angular/app.js') }}"></script>
Hope this help!

keeping safe assets folder in codeigniter

Hi i have this assets folder which has the following folder inside of css, images, uploads, and js folder i put the assets folder outside application. Im wondering that how could i keep it safe so that when users tried to type in the url like for example http:/test.com/assets it will redirect to application folder or somewhat it will says page not found. Cause ive noticed that when i type in the url http://test.com/assets it will go to the assets folder and which is vulnerable and people could see all the folders in the assets folder. can someone help me figued this thing out? Any help is muchly appreciated.
if you want to secure you folder then do one this create html file like this
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
and save it as index.html and put it on your assets folder whenever some try to access your url http://test.com/assets then this index file will execute and its shows Directory access is forbidden.

Spring web development images

Can anybody tell me or give me a link to go to which can tell me how to implement and display images step by step (I'm only beginning) on a webpage from a spring project
I'm using IntelliJ
Thanks
What's the URL of the page? The one that appears in the location bar of your browser?
That is the URL to which relative locations are resolved in the HTML code. So, if the URL is http://localhost/MyApp/foo.html, and the URL of the CSS inside the HTML code is ../../css/style.css, the absolute URL where the browse will try to find the CSS will be http://localhost/MyApp/../../css/style.css, which doesn't make sense.
I prefer always using absolute paths for images and CSS files (and other resources). Using JSTL, that makes it like
<link href="<c:url value='/css/style.css'/>" ...
The <c:url> tag takes care of prepending the application context (/MyApp) to the path.
Note that relative paths inside CSS files are not resolved relative to the page URL, but relative to the location of the CSS file itself. So the path in your CSS file is correct.

How to link assets(images,stylesheet etc) in Views for CodeIgniter 2.1?

I am using CodeIgniter Version 2.1 & trying to link assets like images,stylesheets, javascript files etc in my views by using, header.php:
<link href="<?php base_url();?>css/style.css" rel="stylesheet" />
my controller code, calls the view:
<?php
class Main extends CI_Controller{
public function index() {
$this->load->view('header');
}
The view file from which I am trying to load the asset is located
../application/views/header.php.
the css file is loaded:
../application/views/css/style.css
this does not work. I get 404 - Page not found error.then, I tried moving css/style.css outside ../application directory in webroot. To my surpise, having assets in webroot(outsite ../application/views) seems to work nicely.
Now,
My Question is
Is having our assets directly in webroot, outsite ../application directory right approach? If YES/NO, then why?
If having assets directly in webroot is a good idea, than should I move ../application/views directory in webroot as well? How?
PS: I am new to CodeIgniter framework, so unaware of the best practices
If you see this, the section where .htaccess is used to remove index.php from the urls, that has a rewrite condition:
RewriteCond $1 !^(index\.php|images|robots\.txt)
In this line, images is a folder that will be ignored while mod-rewriting. So, you can replace it by assets, put all your directly linking files there, and happily use them.
RewriteCond $1 !^(index\.php|assets|robots\.txt)
EDIT: my bad, hadn't seen the date the question was asked. nevertheless, should be useful for someone.
It is best to put your assets in the webroot folder. When requesting assest from the server (depending on your setup), it will start from the root directory and work it's way down.
http://yoursite.com/application/views/css/mystyles.css
if it's in the root you only need to go from there
http://yoursite.com/css/mystyles.css
Although it might be worth putting them all inside a folder (/assets) to keep them contained, as well as the ability to write a more effective rewrite rule (if you are trying to remove the index.php from the url) to ignore the single folder instead of all the individual folders (/css, /js, etc)
As for the views folder, it's best if you leave it in the application folder as CodeIgniter has a built in loader that automatically checks /application/views for the view file when you use the code $this->load->view('myview')
Although there are way to move the views folder, if you are new to CI it's probably best to leave it there for now.
For linking css you can do something like:
echo link_tag('css/mystyles.css');
Check this for ref: http://codeigniter.com/user_guide/helpers/html_helper.html

Resources