Load Works on Local Path, Require Doesn'T

load works on local path, require doesn't

If you provide just a filename to require, it will only look in the predefined $LOAD_PATH directories. However, if you provide a path with your filename, it should work:

puts 'This is the first (master) program file.'
require './loadee.rb'
puts 'And back again to the first file.'

You could also add your project's folder to the load path instead:

$LOAD_PATH.unshift File.dirname(__FILE__)
puts 'This is the first (master) program file.'
require 'loadee.rb'
puts 'And back again to the first file.'

And last, you could just use require_relative instead:

puts 'This is the first (master) program file.'
require_relative 'loadee.rb'
puts 'And back again to the first file.'

Cannot open local file - Chrome: Not allowed to load local resource

We use Chrome a lot in the classroom and it is a must to working with local files.

What we have been using is "Web Server for Chrome". You start it up, choose the folder wishing to work with and go to URL (like 127.0.0.1:port you chose)

It is a simple server and cannot use PHP but for simple work, might be your solution:

https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

Android Studio is not loading on the device, local path doesn't exist

Go to your project folder. Open ProjectName folder.

In file Your_Project_name.iml add

<option name="APK_PATH" value="/build/apk/your_app_name-debug-unaligned.apk" />

Or

<option name="APK_PATH" value="/build/outputs/apk/your_app_name-debug-unaligned.apk"/>

In new versions of Android studio

Can't load file from URL, but works with local path

Turns out that I had my openssl.cafile property set to some location that didn't exist.

For some reason no errors were showing when using the commands above.

JS and CSS doesn't load on local

URLs starting with a single / are absolute paths.

They are calculated by taking the current URL and completely replacing the path.

If you start with http://localhost/index.html then you get http://localhost/components/card.js. Your HTTP server will then resolve that to something like: /home/user/work/project/components/card.js and all is good.

If you start with file:///home/user/work/project/index.html then you get file:///components/card.js … which is wrong.


There are a couple of approaches you can take with this.

My preferred one is to treat websites as things that should be accessed over HTTP. There are lots of restrictions if you don't use HTTP, and these kinds of URLs just break. The simple solution is to use a web server.

Another approach is to use relative paths, in which case you need to be explicit about where you link to in terms of directories.

Going from $PROJECT/index.html to $PROJECT/components/card.js needs you to link to components/card.js but going from $PROJECT/example/index.html to $PROJECT/components/card.js needs you to link to ../components/card.js. It's a lot harder to maintain.



My idea was to deliver a folder with all the files and I imagined that he clicking would be able to see all the components and navigate through the pages.

How you deliver to a client will depend on what you negotiate with them.

In very broad terms, however, they are either going to be non-technical (in which case you should deliver them a URL and be responsible to organising the hosting of the final site) or technical (in which case they should be able to handle an instruction to test the code on a web server).

Not loading image from local path in Angular 7

Put the Images folder in assets folder and give the path.

jQuery .load() doesn't work online, but works on my local drive

EDIT
It seems that your server is not serving files of type .txt (when I try to access the URL I get 404), so you need to change the file extension to something else, e.g. .html.

In addition to that, see below on how to use absolute path instead of relative path (this will ensure that your js code works in every page of your website, regardless of the path of the current page being visited).

If the text file is located in the root directory of the website, you should use

$('#p1').load('/file.txt');

instead of

$('#p1').load('file.txt');

(note the '/'). This way it will always work regardless of the current path.

EDIT obviously if the file is in a subdirectory, then it should be something like

$('#p1').load('/path/to/file.txt');

EDIT 2 based on the info you provided it should be

$('#p1').load('/jquery/file.txt');

Why does load/require in irb not load local variables?

require/load is not the same as just copying and pasting the file into irb. You do run the file but files have their own scope in ruby. The local variable you create john is scoped to that file. That means when you define it it is available in the file but not outside it. This is a good feature to have: imagine you have a different file that creates a Dog class and assigns john = Dog.new. When you loaded that file it would change the assignment of john in your first file, breaking any code that depends on john being a person. Many Ruby programs contain hundreds of files -- you can imagine how this would be painful. It's the same thing when you have two methods

def method1
john = Dog.new
end

def method2
john = Person.new
method1()
puts john
end

We want to be able to define variables and do things with them without worrying the other code we call will change them. If you call method2 you'll see that john is still a Person. If calling other methods could change your local variables it would be very hard to reason about what was happening.

Local variables inside files are scoped only to those files just like local variables inside methods are scoped only to those methods. If you want to access them outside the file, just make them constants.

JOHN = Person.new


Related Topics



Leave a reply



Submit