Ruby on Rails Tutorial - 5.26 - Sublime Text "Unable to Save" new file "spec/support/utilities.rb" - ruby-on-rails

I am using Sublime Text 2 while following Michael Hartl's Ruby on Rails Tutorial.
The specific portion of the tutorial to which I am referring can be found at http://ruby.railstutorial.org/book/ruby-on-rails-tutorial (ctrl+F "Listing 5.26").
I am able to create the spec/support file. However, when trying to create the spec/support/utilities.rb file, I receive the message "Unable to save ~/rails_projects/sample_app/spec/support/utilities.rb".
Does anyone know why this might be?
Someone on the Sublime Text forum seems to have had the exact same problem: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8570&p=36922#p36922

This issue sounds like it's a result of incorrect permissions or ownership of the folder. Change directories (cd) so you're outside of the folder where you're creating the .rb file and type:
ls -l
This terminal command lists the permissions attached to all files/folders in that directory. If "root" is listed as the folder owner, change its owner by typing:
sudo chown YOUR_COMP_USER_NAME FOLDER_NAME/
You should now be able to save files from inside that folder.

To diagnose this, first find out if it's an issue in Sublime or your file system:
Does that file already exist? Try looking for it on your file system (not using Sublime).
Verify that you have permission to write to that file. Use "ls -la" on the command line to show the file permissions.
Are you able to create and/or save that file using any different editor, for example TextMate, or Notepad?

The following sublime plugin fixed the Unable to save... bug
https://gist.github.com/3779601

The folder spec/support doesn't exist, and sublime won't create the missing folder, so it errors.
You just need to make the spec/support folder , then sublime will save the file.
I also highly recommend installing the AdvancedNewFile plugin ( Video of it action thanks to Jeffrey Way and NetTuts+ ) , which you can grab straight from Package Control.
It creates files, parent folders if needed, and if you try to create a file that already exists, it opens it instead.

This can happen if you are trying to create the file within a directory that does not currently exist. For ex. I was unable to save
~/rails_projects/sample_app/app/views/shared/_error_messages.html.erb
via the "subl" command from the Terminal because I was missing /shared/ folder. Hope that helps.

so #knice almost had it, I ran into the same problem with permission when starting my first rails project on mavericks.
as mentioned if you run ls -l you'll see your folder / files listed with their permissions
I solved this by changing ownership recursively with the following command from outside my project directory
sudo chown -Rv <your_username> <your_path_and_foldername>
for example if you're in your folder in terminal you should cd .. and then
sudo chown -Rv username ruby_proj/
the -R is for recursive meaning it will apply to all files and folder contained within the folder you specified, and the v after just produces verbose output, showing you which folder and file permissions have been changed.
Hope that helps someone else.

Related

yeoman creates project in Desktop even though I CD into directory

I am having a issue creating a yeoman project. I cd in the directory type yo and it says:
Here is it suppose to asked me project name etc and it wants to throw everything on my desktop not the file I cd into. It defaults to mvn and I want gradle. I even npm uninstall -g generator-jhipster
and reinstalled it and got the same issue.
If you have a .yo-rc.json file in a parent directory, Yeoman will load that configuration and generate from that file instead of prompting. This allows developers to run a yo command from any folder in the project and have it apply to the correct files.
To solve this, remove the .yo-rc.json from the parent directory, in your case /Users/drew/Desktop.
For example, if you are in the directory /Users/drew/Desktop/new-project but /Users/drew/Desktop has a .yo-rc.json inside, Yeoman will change to the parent directory (Desktop), load the configuration, and generate the files from that folder instead of the child folder.
Based on your log it's looks like you are running yo in a folder where a .yo-rc.json is already existing. Careful under windows the .yo-rc.json can be that is of type hidden and you can't see it in explorer. Because of an existing .yo-rc.json you are not asked anymore for info e.g. project name, build tool etc. My recommendation will be to create a new folder run inside yo command

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.

./create: No such file or directory error in terminal window

I am very new to iPhone development and I am looking to work with the PhoneGap framework to create iPhone apps. I installed Phonegap on Mac OS X Lion. I got this error in the terminal window for ./create <project_folder_path> <bundle_id> <project_name>:
./create: No such file or directory
I have searched Google to solve this error, but I can't find any idea from there. Could you please help me solve this issue and run the project? Thanks in advance. Looking forward to your answers.
You probably need to check your current directory with the pwd command, which is what the . is shorthand for. The create executable sits in the Cordova bin directory, not your project directory.
For example, this site shows the required command line to be (spread across multiple lines for readability):
./path/to/cordova-ios/bin/create
/path/to/my_new_cordova_project
com.example.cordova_project_name
CordovaProjectName
In other words, create is separate from your project.
The solution is probably to fully specify the path name of create.
./path/to/cordova-ios/bin ./create
~/<project_folder_path> <bundle_id> <project_name>
This works for me :
Download cordova-3.0.0 and put the folder in your document folder. Expand cordova-ios.zip inside.
Create a folder CordovaTestProject inside your document folder.
Then, open the terminal and try :
./Documents/cordova-3.0.0/cordova-ios/bin/create /Users/<username>/Documents/CordovaXY/HelloWorld org.apache.cordova.HelloWorld HelloWorld
replace <username> by your username. You can get it with pwd in terminal. In terminal, type "pwd" and you will get your username
Make sure that you are inside \phonegap-2.7.0\lib\ios\bin before entering ./create command. Refer the Blog Tutorial for a simple and straight forward explanation of PhoneGap instalation in Mac for iOS and creating a new project.

Static Pages >> sh.exe"; subl: command not found

I'm going through an RoR guide, and i'm stuck at a problem in topic "Static Pages" and currently I'm using the text editor Sublime Text 2 and whenever i follow instructions and do:
$subl .
or try
$subl public/hello.html
it outputs:
sh.exe" subl: command not found
any help would be very much appreciated..
-Marc
if using ruby version manager (i am only assuming because i had this problem), then the suggested command for the symlink must be modified at the user path:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/.rvm/bin/subl
notice the .rvm directory has been added to the path.
I've had a similar issue, the paths in $PATH were correct, and when I browsed to my local bin folder:
cd /usr/local/bin/
I could see the subl file / shortcut.
After pening this folder in finder with:
open .
I could see the icon looked incorrect (white), perhaps a previous version. Double clicking it also gave an error, so I manually copied the subl file over, after expanding contents of the Sublime Text 2.app.
If you drag the file over, it will create a shortcut, if that doesn't work then first duplicate the subl file in its original position, then drag over the duplicate and rename correctly. Or just give the correct permissions on it.
Hope this helps

Where is the .rspec configuration file located exactly?

Working through the Ruby on Rails Tutorial and stuck here "To run RSpec and Spork with Autotest, we need to configure RSpec to use the --drb option by default, which we can arrange by adding it to the .rspec configuration file in the Rails root directory (Listing 3.14)."
When I search my file structure I can not find a single file with .rspec file extension? How do I access this file to update the configuration?
If you are using a mac you will not see these files just like you will not see the gitignore file
what you need to do in order to access this file is from the root directory of the app just click (command line)
mate .rspec
this will open the file if it's there, and if not, it will create it.
If you add gem 'rspec-rails' to your Gemfile, you can use the rails g rspec:install command.
This will create the .rspec file in the root of the Rails application. It will also create a spec folder and a file inside it 'spec_helper.rb'
If you do not want to write this command, you may simply create the file manually. If you are using a linux machine, the hidden files can be seen with a <ctrl-h> command. You may also try the ls -a in any unix terminal to see all hidden and non hidden files.
Files on mac that begin with . are not shown by default. In Terminal, if you type ls -a you'll see all of the "dotfiles" that are in the folder.
If this file doesn't exist yet (it probably doesn't) then you just need to create it using your favorite editor.

Resources