Running RoR application in Windows, which was developed in Linux - ruby-on-rails

I have a RoR application working in Linux environment. I have to move that to windows environment. When I run
bundle exec rails server
I see this error
There was a Errno::ENOENT while loading omniauth-cas.gemspec:
No such file or directory - git ls-files -- bin/* from
When I opened the files, I saw these lines
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split
In these lines, I can understand that ls-files is a Linux command, which never work in Windows. With what should I replace this statement so that it runs in windows?

Start by figuring out what your current working directory is for your running script.
Add this line at the beginning:
puts Dir.pwd.
This will tell you in which current working directory ruby is running your script. You will most likely see it's not where you assume it is. Then make sure you're specifying pathnames properly for windows. See the docs here how to properly format pathnames for windows:
http://www.ruby-doc.org/core/classes/IO.html
Then either use Dir.chdir to change the working directory to the place where text.txt is, or specify the absolute pathname to the file according to the instructions in the IO docs above. That SHOULD do it...
Adding a 3rd solution which might be the most convenient one if you're putting the text files among your script files:
Dir.chdir(File.dirname(__FILE__))
This will automatically change the current working directory to the same directory as the .rb file that is running the script.

Related

Ruby change directory in code

So, I've came across an issue where I delete the current folder where my ruby script is executing ex:
/home/user/scriptfolder
Now i have my ruby gem running and I do this:
mycommand --deletefull
now mycommand is an GLI command, which should delete the content of the folder and the folder itself. I do that by using my custom class:
ClientModuleDir.rm_f(path)
now after deleting it I want to just do cd ..
however I've tried several methods:
system('cd ..')
Dir.chdir(dir) #dir is abs path without the scripfolder name, i've tried every combination with this command, nothing works so far.
However these methods are not working.
I still am in the
/home/user/scriptfolder
after executing these commands, but the folder DOES NOT EXIST. When I manually do cd .. and i do ls the folder is not there.
How do I change "physically" the folder in ruby code ?
The current working directory is always kept for the current program only. Changing the working directory in a program won't affect any other running programs, including its parent.
Thus, when you delete the directory in your Ruby script and change the working directory of the Ruby process one level down, this won't affect the shell process which has started your Ruby script.

Ruby on Rails - bin files shebang causing issues (Mac)

So for the files in the /bin directory of a normal rails installation (bin/rails, bin/rake, bin/bundle), the shebang at the top of the file is:
#!/usr/bin/env ruby.exe
But when I run bin/rails, for example, I get the error:
env: ruby.exe: No such file or directory
When I remove the .exe from the end of the shebang, everything works fine. But I was just curious:
Why is this necessary
How to deal with versioning, since the other developer working on this doesn't need to remove the .exe. It's suggested to keep the bin folder in the repo, so I'd prefer to just get the .exe version working if anything.
There are no .exe files on Mac OS X or on Linux. On those platforms the Ruby executable is just called ruby.
For compatibility to those operating systems, your first line should look like this:
#!/usr/bin/env ruby

'rake' is not recognized as an internal or external command, operable program or batch file

Minutes ago, I downloaded the oscurrency code from github, and I'm installing oscurrency on heroku. Everything seemed to be going perfectly until this command:
rake heroku:install
on the command line, in the directory where I downloaded the source code. I get the error:
'rake' is not recognized as an internal or external command, operable program or batch file.
I'm following the installation instructions at heroku here:
https://github.com/oscurrency/oscurrency/wiki/Heroku-Deployment-Guide
The command "rake heroku:install" is in the third paragraph from the bottom.
The code I downloaded came in a top-level folder called oscurrency. I downloaded that onto my laptop in C:\me\oscurrency. I was issuing the command in that directory when I got the error. I tried issuing the command in the folder C:\me\oscurrency\oscurrency -- same error.
Maybe the command has changed for some reason. Anybody have an idea what's going wrong?
Your problem is most likely that the command prompt is looking for a file named rake.exe and not able to find it because your PATH environment variable is not set to include that directory. I suspect that the rails command won't work either. You should add the ruby install directory (probably C:\Program Files\Ruby on Rails\bin\ to your PATH environment variable.
To do this, open your Computer Properties by right-clicking My Computer and selecting Properties, then find the "Advanced System Settings" link. Click the "Environment Variables" button at the bottom, and paste the path to that directory into the PATH variable, separating it with a semicolon.

Bundle command not found error in capistrano deployment

I am using capistrano deployment.
These errors i m getting after cap deploy
Command 'bundle' is available in '/usr/local/bin/bundle'
The command could not be located because '/usr/local/bin' is not included in the PATH environment variable.
bundle: command not found
Please help
It looks like you need to add the /user/local/bin folder to the path on the target system. Whatever login you are logging in as with Capistrano, find the profile that contains the path, and add it.
Or, add /usr/local/bin to the master path (the actual file depends on the operating system and version. If you provide the operating system and shell, we can tell you the file to look for)

How do I save a ruby file? (error)

I am receiving the error No such file or directory in my command line and I think it's because I am not saving the ruby files somewhere specific. All I did was create a random folder where I would save my ruby files.
Do I need to save my scripts in the original ruby folder? Thanks!
** This is Windows 7.
More info -
All I did was make a simple file named "Matz.rb" because I'm currently reading the O'reilly Ruby book. In my code all I wrote was puts "Hello Matz". I saved this on my desktop. When I go to the command line it and I write ruby matz.rb it says "ruby: No such file or directory -- matz.rb " Please help :(
If this has something to do with PATH or shells, I honestly have no idea what those really are because I just started coding last night.
You are most likely not in the right folder. You somehow need to tell the ruby interpreter where it is looking for the file.
Either make sure you're in the right folder - the cd command allows you to change location:
cd C:\Users\Username\Desktop
ruby Matz.rb
or specify the path explicitly:
ruby C:\Users\Username\Desktop\Matz.rb
By default, the ruby interpreter will look in your current directory (the location shown in your prompt) for whatever filename you give it.
Edit: I'll attempt to explain what I mean step-by-step.
When you initially open the command prompt, it will indicate what folder you are in (your "current working directory") in the prompt:
C:\Users\YourUsername >
In the above example, you are working in the C:\Users\YourUsername folder.
You can move directories using the cd command. For example, typing cd Desktop moves you into the folder called Desktop, assuming such a folder exists in your current location
You can move to another folder outside your current folder by specifying explicitly where you want to be: cd C:\Another\Place
When you run a ruby command such as ruby Matz.rb, the system knows how to find the ruby program because the installer placed its location into the PATH environment variable. Don't worry about this too much, this just explains the "magic" by which it knows what ruby means, no matter where you are.
Ruby finds the file you specify (in the above example, Matz.rb) by looking in the current directory. To re-iterate, it is looking in whatever folder is written right there in your prompt.
You can tell ruby to look outside the current folder by specifying the full path (as shown in the answer above).
To go from a new command window that you've just opened, to typing ruby Matz.rb and having it work, you need to do the following:
Move to the correct directory
Run the command
If we assume your username is alex and you have a folder on your desktop called "rubycode", which contains Matz.rb, you could do this:
Open a command prompt, which will most likely start in C:\Users\Alex
Move to the rubycode folder on your desktop: cd Desktop\rubycode. All subsequent commands will be working from within this folder.
Run the ruby command, specifying the file: ruby Matz.rb
Continue to run ruby commands as you learn ruby.
I hope that makes sense.

Resources