I'm using the railstutorial at http://ruby.railstutorial.org/chapters/rails-flavored-ruby#sec:a_user_class
I've been told to type require './example_user' but... I get this error
LoadError: cannot load such file -- example_user
from /Users/snook3/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require'
and then further and further errors
I imagine that I'm not linking correctly to that folder, can anyone let me know where I should be linking too?
Yes, just move the file to the actual root directoy. Doing mv example_user.rb* / should do it.
Also, don't worry if after requiring the file, you get a return of "true" instead of ["User"].
You can use
Rails.root
to get your current Rails project root.
So
require Rails.root + 'path_to_example_user'
would load the file.
You can also try the reload! command, which will reload the whole Rails environment.
The file should end with .rb:
require './example_user' #will not work
require './example_user.rb' #will work
To rename the file, use the following command line (not in the rails console):
mv example_user example_user.rb
try using absolute path for the file... something like this:
require '/Users/snook3/my/project/folder/example_user.rb'
No need to specify the full path, simply append .rb to the filename: require './example_user.rb'.
I had this exact same problem, but not being very familiar with Unix I can only explain it like this.
1) I created the example_user.rb file in Sublime Text 2 and saved it to the application root folder.
2) The "require" wasn't working for me, just like the OP. Even though I could see the file there in the folder.
3) However, opening up a Terminal window, navigating to the application root, and entering "dir", I could then see that the filename had a "/ " before it!? Not sure how/why that happened, or why it wasn't visible in Explorer (or whatever the Unix equivalent of that is called--Nautilus?).
4) After renaming the file from within Terminal, it all worked. But would love an explanation of what went wrong if this makes sense to any of you Unix/Rails folks.
Try
touch example_user.rb
in Unix terminal. And then add code to this file.
The tutorial tells you to "create the file example_user.rb in your application root directory". I mistakenly initially put it in the app folder and got the same error message.
If you instead move the file into your project root directory, then require './example_user' will work.
Related
Please advise. This SQLPlus call:
SQL > #dba_files_all
...is not working.
SP2-0310: unable to open file "dba_files_all.sql"
How can I resolve the error?
You need to provide the path of the file as string.
Put the path in double quotes and it will work.
For example:
#"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";
I encountered this error when attempting to execute a file in the same folder as the calling function. In my example, this process:
Was executed in SQL Developer;
Has been a long-standing part of my system (moving a setup file with some settings and variable names through various folders; those folder names include the feature IDs and a short description);
Has worked fine in the past;
Did not require any pathing in my case because the files were in the same folder;
Failed on the most recent attempt with the error above (SP2-0310).
The issue in my situation was that the folder name in which it failed included a character (#) that was valid for a Windows file name, but confusing to SQL Developer.
1.Use absolute path:
/u01/app/oaracle/test.sql
2.Check the path to see if script exists:
ls -l /u01/app/oaracle/test.sql
Note that
SQL> #some_file.sql
means that sql app you are using will look for that using "absolute path" so if you want to use "relative path" use following format [add ?]
SQL> #?some_file.sql
else, use "full path" with first command.
All the answers so far imply that absolute paths are required. That aren't. Relative paths in sql is pretty universal in sql tools. Sometimes, you have to configure a lost default configuration such as in the case of SQLDeveloper as explained in this answer:
https://stackoverflow.com/a/24003529/442968
I just run into same error when I was trying to unlock oe schema.
While reading the error, I realized that when I run the following line:
>SQL #?/demo/schema/order_entry/oe_main.sql
The error returned a completely different path
SP2-0310: unable to open file "C:/app/USER/product/18.0.0/dbhomeXE/demo/schema/order_entry/oe_main.sql"
Thus I copied my sql file to the path specified by the error and everything worked. I recommend that you do the same. Check the path in the error and adjust accordingly.
Use absolute path or run sqlplus command from a shell/dos that points to the path of the script. Also, to use a masterscript, refer to subscripts with ##.
verify that your file has an extension .sql not .sql.txt
usually when I have a question about something remotely software related I find that someone else has already asked the very same thing, and gotten good answers that works for me too.
This time, though, I've failed to find an answer to my predicament.
Here we go:
I'm currently trying to move up my Lua-programming a notch or three and want to use modules. So, I've got a structure like this:
main.lua
foo/bar.lua
Now, in main.lua I do
require("foo.bar")
which fails,
main.lua:1 module 'foo.bar' not found:
no field package.preload['foo.bar']
no file 'foo.bar.lua'
no file 'foo.bar.lua'
no file 'foo.lua'
Ok, something might be wrong with my package.path so I use package.searchpath("foo.bar", package.path) to see what I', doing wrong.
The problem is that package.searchpath resolves foo.bar to foo/bar.lua which is exactly right.
As I've understood it, package.searchpath tries to find the module in the same way as require, but there seems to be som glitch in my case.
What strikes me as odd is the repetition of the no file 'foo.bar.lua' in the error output
Have I misunderstood the use of require?
I'm using LuaJIT-2.0.0 to run my chunks
Update:
I'm using LuaJIT-2.0.0 to run my chunks <- This was the reason for my problem, stock Lua-5.2.2 behaves as expected
package.path = debug.getinfo(1,"S").source:match[[^#?(.*[\/])[^\/]-$]] .."?.lua;".. package.path
require("foo.bar")
This line causes require to look in the same directory as the
current file when asked to load other files. If you want it to instead
search a directory relative to the current directory, insert the
relative path between " and ?.lua
Here is part of require description:
[...] Otherwise require searches for a Lua loader using the path stored in
package.path. If that also fails, it searches for a C loader using the
path stored in package.cpath. If that also fails, it tries an
all-in-one loader (see package.loaders).
Default path for package.path is always the .exe that executes specified script.
I am trying to execute phantom.js module from rails. So far I've successfully installed the binary and the path for phantomjs seems to be working fine.
However when I try to run it from a rails app using backtick (for example: phantomjs rasterize.js http://google.com 1.jpg), it says No such file or directory.
I think the reason is it can't find the path for rasterize.js
I tried putting the rasterize.js file in #{Rails.root}, inside public folder, inside controller folder but nothing works.
How can I solve this problem?
====
UPDATE: To clarify, i'm posting which code works inside my controller and which doesn't.
def create
'phantomjs'
end
<= Above code doesn't spit out path error, and when I send a request from the browser, phantomjs process does get invoked, resulting in opening up the console in the server side.
def create
'phantomjs rasterize.js'
end
<= This doesn't work, and it spits out error saying "No such file or directory", and that's why I think it has to do with rails not being able to find rasterize.js's path. I tried putting rasterize.js inside public folder, inside controllers folder, and inside the main directory: #{Rails.root}, but it's always the same.
Interesting... I've been trying all kinds of combinations and finally ran into a case that works, and it's not what I expected:
%x("/usr/local/bin/phantomjs /Users/e/Dropbox/Projects/rails/screenshots/rasterize.js http://google.com app/assets/images/2709.jpg")
<= This doesn't work.
system("/usr/local/bin/phantomjs /Users/e/Dropbox/Projects/rails/screenshots/rasterize.js http://google.com app/assets/images/2709.jpg")
<= This works.
I thought these all work internally the same, except for return values? Maybe I was wrong?
Let say your command is cmd.It is good to know that %(cmd) and exec(cmd), change the process you are on so if you are in rails and changed the directory it will exit. On the other hand `cmd` and system(cmd) will let you continute working.
I learned that from this blog. http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html
When I use the "Show me the page" step, with Capybara / Cucumber, can I control where the files get output? I can't seem to find the config for this, and my google fu is failing me.
Right now it appears that by default they go to the root of my rails folder and clutter up things there.
There is indeed a config option that allows you to specify where to output the files:
Capybara.save_and_open_page_path
I believe it was added in the latest version (0.3.9)
In your env.rb file you can do something like:
Capybara.save_and_open_page_path = '/Users/jsboulanger/my-rails-project/tmp'
In Capybara 2.10, Capybara::save_and_open_page= is deprecated. Instead, call Capybara::save_path=
Nice. Thanks for this.
To be really neat about it I added the config line to config/environments/test.rb, since you generally only use capybara in test, and that works fine.
Since there's a bunch of subfolders in tmp/ I used:
Capybara.save_and_open_page_path = 'tmp/capybara'
and created that folder.
I make a call just like this:
value = ./simulated_annealing
Which is a C Object file, but Rails tells me it cannot find that file. I
put it in the same dir that the rest of the models files (since it's
called by one of those models), but I guess it should be in any other
place.
I've tried that outside Ruby and it works great.
What do I have to do?
The thing is, when you say:
./simulated_annealing
you're explicitly saying: run file named simulated_annealing which is found in the current directory. That's what the ./ means. If the file's located elsewhere you need to provide the path to it, or add that path to the environment variable $PATH. So, you should replace that line with:
/path/to/simulated_annealing
where /path/to represents the actual path.
The best option is to use an absolute path for running the program. For ex.,
you can create a directory "bin" under your rails application top level
directory. Place your program under "bin" directory. Then you can
execute the program something like:
cmd = "#{RAILS_ROOT}/bin/cbin arg1 arg2"
value = `#{cmd}`