rails console yaml parse error - applying solutions - ruby-on-rails

BACKGROUND Complete newbie to coding working thro’ RailsTutorial on a windows 7 PC– I’ve stalled on chap 4.2 with an YAML error running “rails console” from a command prompt with Ruby on Rails.
I need tips on how to interpret and use some specific answers (below) that I found posted on stackoverflow/google groups/github.
I’ve tried to meet forum criteria for questions. If any of my confusions are too basic here please let me know which & where else I might try.
The error -
~\Sites\sample_app rails console
C:/a_installers/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/psych.rb:154:in 'parse
: (<unknown>): couldn't parse YAML at line 44 column 11 (Psych::SyntaxError)
from C:/a_installers/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/psych.rb:
54:in 'parse_stream'
(40 more lines like this)
Not sure what useful context I can supply.. possibly that I used Railsinstaller and later Pik (instead of RVM) on Windows 7, that I installed ralis/ruby programs under c:\a_installers\railsInstaller and that I’ve updated PATH to include ruby bin folders.
QUESTION The advice I'm having difficulty interpreting/using is..
rails error, couldn't parse YAML suggests
a. Run the YAML code through yamlint.com
Which YAML file? All those in the error listing? I think I’m running rails console from my installed rails program area (above), there I found 60 odd files with “ *.yml “ – do I have to run all these through YAMLlint.com?
b. Manually Fix the YAML code
One example given was " fixing invalid yaml " involving splitting yaml code for a local date into lines.This was not applicable – I couldn’t find any such code in any of the 60 odd “ *.yml “ files under railsinstaller on my system
c. “load the old YAML parser (syck) with code xxx in config/boot.rb”
Two problems…
(1) I couldn’t find boot.rb in my the rails/ruby program area
(2) I’m torn between two contrary views expressed
“Psych is the new one, the one you should be using you have some invalid yaml somewhere.”
And
“wrong… ruby should use a parser that is both maintained and supports existing usage, even if that usage is further from the spec. If only there were such a thing. Until there is, they should use syck..”
In summary, not sure which files to amend, how to do that, how to check that. if it’s advisable instead to do a workaround (reverting to syck) and if so in which directory and with which files.
another source rails-yaml-config-best-practice advised
“configure parameter inside environment.rb.” use a github code called “settings logic”
Not sure how to do this..do I need to learn YAML? Tutorial hasn’t even started Ruby yet – is this
Not sure where to do this – couldn’t find environment.rb in my rails/ruby program area – it seems to be part of my application (sample_app)
In ..Settings_logic …the notes seem to bring me full circle to 1. above.
“..Note: Certain Ruby/Bundler versions include a version of the Psych YAML parser which incorrectly handles merges (the << in the example above.) If your default settings seem to be overwriting your environment-specific settings, including the following lines in your config/boot.rb file may solve the problem:
require 'yaml'
YAML::ENGINE.yamler= 'syck'
To apply this solution I still need to resolve question 1 c (2)
3 General advice - My inability to start rails console seems an absolute barrier for me to use ROR- a couple of general questions - Do practitioners use rails console for actual development or just learning? Can I learn RoR without rails console?
Many thanks for your patience, time and attention.

Related

/usr/bin/ruby file just contains gibberish and the word 'ELF'; safe to delete this/is this the file I really need?

I'm trying to install the Ruby gem foreverb, to keep my server process running when SSH disconnects, and also for improved understanding of the people visiting my site.
On following this guide:
https://github.com/DAddYE/foreverb
It mentioned to write some code in /usr/bin/ruby so I dutifully opened the file and looked inside. Instead of what I expected (either a blank file or something that looks like Ruby code) I was instead greeted with this:
^?ELF^B^A^A^#^#^#^#^#^#^#^#^#^C^#>^#^A^#^#^#à^H^#^#^#^#^#^##^#^#^#^#^#^#^#^P^Q^#^#^#^#^#^#^#^#^#^##^#8^# ^##^#^[^#^Z^#^F^#^#^#^E^#^#^##^#^#^#^#^#^#^##^#^#^#^#^#^#^##^#^#^#^#^#^#^#ø^A^#^#^#^#^#^#ø^A^#^#^#^#^#^#^H^#^#^#^#^#^#^#^C^#^#^#^D^#^#^#8^B^#^#^#^#^#^#8^B^#^#^#^#^#^#8^B^#^#^#^#^#^#^\^#^#^#^#^#^#^#^\^#^#^#^#^#^#^#^A^#^#^#^#^#^#^#^A^#^#^#^E^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#¼^K^#^#^#^#^#^#¼^K^#^#^#^#^#^#^#^# ^#^#^#^#^#^A^#^#^#^F^#^#^# ^M^#^#^#^#^#^# ^M ^#^#^#^#^# ^M ^#^#^#^#^#p^B^#^#^#^#^#^#x^B^#^#^#^#^#^#^#^# ^#^#^#^#^#^B^#^#^#^F^#^#^#¸^M^#^#^#^#^#^#¸^M ^#^#^#^#^#¸^M ^#^#^#^#^#Ð^A^#^#^#^#^#^#Ð^A^#^#^#^#^#^#^H^#^#^#^#^#^#^#^D^#^#^#^D^#^#^#T^B^#^#^#^#^#^#T^B^#^#^#^#^#^#T^B^#^#^#^#^#^#D^#^#^#^#^#^#^#D^#^#^#^#^#^#^#^D^#^#^#^#^#^#^#Påtd^D^#^#^#<98>
^#^#^#^#^#^#<98>
^#^#^#^#^#^#<98>
Not entirely sure what it is, but pretty sure it shouldn't be there. Is it file corruption, as it doesn't look like what I'd generally consider to be file corruption? While I assume it's probably not doing anything useful at the moment, does the presence of semi-arbirary strings in this file represent a problem with my Ruby installation which I need to fix? Is there perhaps another location or set of locations where the right file might be, and perhaps this one isn't being used?
I notice I have a lot of problems with my server, and often find I have to randomly reinstall gems which seem to disappear from my system, usually after the SSH disconnects. Could this file be something to do with that?
It seems odd to me that if this is the location of an important Ruby system file that my Ruby installation should work at all, but it does seem to... Might it be left over from a previously broken installation? I'm only just progressing out of the beginner stages with Ruby, so any insight into what the file does, why it's important and, particularly, how I should progress would be extremely helpful. Also, any suggestions for further reading on Ruby framework eco system which might help me better understand the inner working of stuff like this would hopefully save me from having to take up people's time here with similar questions in the future, though I understand that's a little outside the usual remit for the site.

Psych Error: `parse': (<unknown>): could not find expected

`':' while scanning a simple key at line 16 column 1(Psych::SyntaxError)
I'm working on a Rails application tutorial and have had the above error come up several times. When I was getting this error it seemed to only be a problem if I used one particular terminal window. I have since restarted the computer and now it is a problem regardless of what I do.
I went to the project on github and copied the information in 'secrets.yml' into my file in case that was the issue but doesn't help. In fact I'm not sure if that is even the file causing the problem because when I shift the code in that file and save it I still get the same error; at those times it points to a line that is now blank in the 'secrets.yml'
Update.
now I am getting this when i run this command
rails generate simple_form:install --foundation
-bash: $: command not found.
only change I did was start the code in 'secrets.yml' lower down, and i added a secret key to my .bash_profile, as it was suggested in tutorial and I had not done it before, and thought that might be the problem.
Update 2
shut down terminal and tied again and getting the original problem "psyche Error" Yes, thank you for your feedback, I too, although not sure why, suspect it is to do with the 'secret' file or could it be changes the tutorial told me to make to my .bash_profile. The instructions were not very clear, wondering if that is where I messed up. If that is so then I would not know how to fix that.
The Psych gem is the wrapper around libyaml and used within Ruby's YAML class, so it's not surprising you think it could be the 'secrets.yml'; a YAML config file. I'd stay the course and find what isn't being formatted correctly.

ruby include trying too many locations

I'm helping someone diagnose some slowness with their RoR applications. I'm not that deep into ruby development, but by running an strace on the ruby process, I noticed the following oddity:
For presumably every .rb file included, the ruby process checks about 110 different locations for the file to include, with all but 1 returning ENOENT. These paths include many non-existent permutations on local directories and gem installation directories. Ironically, the 8th location attempted finds the correct path, but ruby then goes on to try another 100 invalid locations before going back and opening the file it had found at the beginning of the search.
The whole search process takes almost 30ms per included .rb file, which cumulatively means that page takes so long to load that the site is unusable.
I've posted a sample of the strace output in case it is helpful here: http://pastebin.com/t9LD89dr
So, why is it doing this, and how do I make it stop?
This is a known problem with Ruby's require... apparently they're going to fix it with Ruby 1.9.3.
So, this slowness is hard to avoid when spinning up a Ruby app.

For Ruby on Rails, when we run "rails server" (or script/server), what is the sequence of events happening?

I know environment.rb, environments/development.rb, initializers/foobar.rb will run one by one and in this order (as I put some print statements at the top of those files and see the sequence).
Beside these files, which files get run or get looked at, and in what sequence (update: and what causes it to happen?), when we start a Rails server?
This should help you find out it detail:
For Current Rails (3.0.x): http://guides.rubyonrails.org/initialization.html (thanks #Jack Chu)
For Edge Rails (3.1.x): http://ryanbigg.com/guides/initialization.html
For older Rails (from circa 2008): http://railsguts.com/initialization.html

Rubys on Rails project Using Aptana

I am having a major issue with creating a Rails Project on Aptana (using mac os x). Basically, when i try starting a Rails project and name a file, it comes back with an error saying:
"!!! Path to log file not valid: /Users/fab/Documents/Aptana Studio Workspace/test.rb/log/mongrel.log mongrel::start reported an error. Use mongrel_rails mongrel::start -h to get help."
and then a pop up comes up saying: "Rename the directory to no longer have a space"
After all this, i tried renaming the directory without spaces, but then when i went back to create a new project again it came back with this pop up that says "resource'/fab/public'does not exist." Under this there is a list of two options: "periodic workshop save" and "replace project index file."
What does this mean, and how can i fix the problem?
Any advise would be much appreciated!
Omarj
Mongrel used to have a bug with writing log files, and for whatever reason it's trying to create a path relative to a file (rather than a folder) in your case. i think they also had issues with spaces in the path.
Do NOT rename your workspace path, or Studio/RadRails won't see the files anymore (as you saw above) - because you moved them.
I suggest renaming the folder back. This question is pretty stale, so mongrel is no longer widely used. you could try one of the other server types, like webrick.
Hey, I don't have an answer to your question. However, would advise you that if you are starting to get your hands dirty with Ruby and Rails, then consider TextMate as your IDE instead of RadRails.

Resources