Rails project won't start - error unexpected : expecting $end - ruby-on-rails

I wanted to get ribbot an open source code from this git repository. I have already downloaded rails and its necessary gems, as well as mongo db and have "bundle installed".
However I get the following error when running the project.
How can this be solved?
/Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load': /Users/hansarijanto/Desktop/Impact/ribbot/config/initializers/session_store.rb:4:
syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_ribbot_session', :domain =>...
I have traced the file with the syntax error which is session_store.rb which currently looks like this:
# Be sure to restart your server when you modify this file.
# See environment specific overrides also
Ribbot::Application.config.session_store :cookie_store, key: '_ribbot_session', :domain => :all, :expire_after => 10.years
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# Ribbot::Application.config.session_store :active_record_sto

You're using Ruby 1.8 but are using Ruby 1.9 hash syntax in your config/initializers/session_store.rb. The following snippet:
key: '_ribbot_session'
should be
:key => '_ribbot_session'

since ribbot is using ruby 1.9 you should update your ruby version, rather than change the code to make it work, the current ruby version is 1.9.3
http://www.ruby-lang.org/en/downloads/
install instructions
if you're using mac OS:
http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac
if you're using ubuntu linux:
http://www.rubyinside.com/how-to-install-ruby-1-9-2-and-rails-3-0-on-ubuntu-10-10-4148.html
if you're using windows:
http://rubyinstaller.org/

Related

Tried to load unspecified class: ActiveSupport::TimeWithZone - Psych::DisallowedClass

Does anyone know how to fix this exception? Not sure if it's related but it is falling on #discard method calling from discard gem.
if object.discard
# Psych::DisallowedClass:
# Tried to load unspecified class: ActiveSupport::TimeWithZone
I've tried each of the following config settings added to config/application.rb but the issue still persists(no spring running, no preloading)
# config.active_record.yaml_column_permitted_classes = [Symbol, Hash, Array, ActiveSupport::HashWithIndifferentAccess, ActiveSupport::TimeWithZone, Time]
# config.active_record.use_yaml_unsafe_load
# config.active_support.use_yaml_unsafe_load
Ruby version: 3.1.2 |
Rails version: 6.1.7
Related question:
Upgrading to Ruby 3.1 causes Psych::DisallowedClass exception when using YAML.load_file
As a temporary workaround, I've rolled back to 6.1.6 Rails version but I'm looking for a proper solution to this issue.

rest-open-uri on heroku with ruby 2.0

Since the default encoding is now utf-8 for Ruby 2.0, the rest-open-uri gem throws the following error on heroku:
/app/vendor/bundle/ruby/2.0.0/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require': /app/vendor/bundle/ruby/2.0.0/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb:413: invalid multibyte escape: /[\r\n\t !#-[]-~\x80-\xff]+|(\[\x00-\x7f])/ (SyntaxError)
I need to change the following line in rest-open-uri.rb. How can I access this file on heroku?
lib/ruby/gems/2.0.0/gems/rest-open-uri-1.0.0/lib/rest-open-uri.rb
# encoding: US-ASCII
rest-open-uri looks like a dead project. Do you want to get in the business of patching up 8 year old code to get your application to work?
It looks like rf-rest-open-uri is a more up-to-date fork of that project, have you tried it? I don't see any encoding instruction in that gem's rest-open-uri.rb source file.

How to set the `BUNDLE_PATH` value related to the RVM "Integration via ':default_environment'"?

I am running Ubuntu 10.04 Lucid, Ruby 1.9.3p125, Ruby on Rails 3.2.2 and RVM 1.10.3. I am trying to properly set the BUNDLE_PATH value related to the RVM "Integration via ':default_environment'".
At this time in my deploy.rb file I have (note the commented BUNDLE_PATH hash key):
set :default_environment, {
'PATH' => "/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games",
'RUBY_VERSION' => '1.9.3p125',
'GEM_HOME' => "/usr/local/rvm/gems/ruby-1.9.3-p125",
'GEM_PATH' => "/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125#global"
# 'BUNDLE_PATH' => '/path/to/.rvm/gems/ree-1.8.7-2010.01' # If you are using bundler.
}
Since I am using Bundler to manage my gems, I would like to set that value as well as it should be made. What is really BUNDLE_PATH? How can I set that (that is, what value I must consider)?
Please use the first section of integration with capistrano plugin
Also there is integration gem with bundler - I have used both in my example app - https://github.com/mpapis/ad
If you update RVM to head version in your system and on server you can use the new method of reading ruby version from configuration file, start with update:
rvm get head
Then check this line of deploy.rb: https://github.com/mpapis/ad/blob/master/config/deploy.rb#L9
And use one of the new configuration files not needing trusting: https://github.com/mpapis/ad/blob/master/Gemfile
#ruby=1.9.3-p125
#ruby-gemset=my-app
This should automatically select your ruby from Gemfile comment, just do not forget to remove .rvmrc as it's for now selected as the primary format to specify your ruby.

"uninitialized constant Etc" when running Ruby application

A few applications on my server relying on Ruby and Ruby On Rails seem to have stopped working. Or atleast partially so. I managed to get the web gui of the application in question to start functioning again by reinstalling different part of Ruby. But I most likley broke something else in the process.
I have managed to track it down using some tests and it seems like Etc is somehow not found by the program when it runs.
I tested by
ruby -e 'puts Etc.getpwnam("apache").uid'
and got
uninitialized constant Etc
If I instead tested
ruby -r etc -e 'puts Etc.getpwnam("apache").uid'
I get the correct answer
48
This is running on an Amahi6 server (running Fedora Core 14 64bit).
Example on the code in question in the actual application that fails is
#!/usr/bin/env ruby
# Amahi Home Server
# Copyright (C) 2007-2010 Amahi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v3
# (29 June 2007), as published in the COPYING file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# file COPYING for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Amahi
# team at http://www.amahi.org/ under "Contact Us."
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/runner'
require 'optparse'
# switch to apache:users first
uid = Etc.getpwnam("apache").uid
gid = Etc.getgrnam("users").gid
Process.gid = gid
Process.egid = gid
Process.uid = uid
Process.euid = uid
...
this fails with the same
uninitialized constant Etc
Clarification: I have NOT changed this code at all and it has worked in it's current state before
What could it be that I have messed up? :)
UPDATE:
Ruby installed now is version 1.8.7
UPDATE 2:
If I try to manually add a require for rubygems and etc it fails, but complains about another package. So I think there is something fundamentally messed up with the core of my ruby.
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55:
uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support.rb:56
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from
/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record.rb:25
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from /var/hda/platform/html/script/install-app:70
Ended up being that the versions of rails and gems were to new. Downgraded to gems 1.3.7 and rails 2.3.8.
gem update --system 1.3.7
gem uninstall rails
gem install rails --version 2.3.8
You seem to be missing require 'rubygems' and require 'etc' (put them below require 'optparse')
remember about 'rubygems',
commandline:
ruby -rubygems -e 'puts Etc.getpwnam("apache").uid'
script:
require 'rubygems'
puts Etc.getpwnam("apache").uid

Getting Rails to play with Hpricot

I'm trying to get Hpricot working with Rails on my dev machine.
I've installed Hpricot [0.8.1] using the standard 'gem install hpricot' and confirmed it works fine with my standard Ruby installation [1.8.7]; however when I try the same with my Rails [2.1.0] installation, I get an error -
TypeError: superclass mismatch for class BogusETag from /usr/lib/ruby/1.8/hpricot/tag.rb:130
Seems like there's some kind of conflict, but googling the error hasn't turned up any useful information.
Any ideas ? Thanks in advance.
If you're free to choose your HTML parsing library, switch it.
Why, the creator of Hpricot, recently posted that you should better use Nokogiri instead of HPricot, nowadays.
This error occurs because there is no compiled library for the platform. To solve this for your current hpricot version, go to your rails directory dir and do the following (this assumes you are using an unpacked gem - this problem wouldn't arrise otherwise, unless your OS has been upgraded since installing the gem):
cd vendor/gems/hpricot-0.6/ext/hpricot_scan/
ruby extconf.rb
make
Then copy the compiled library to the correct platform dir for your system. Each version of OS X has a slightly different platform name, so mine (Snow Leopard) appears as:
ruby-1.8.6-p383 > RUBY_PLATFORM
=> "i686-darwin10.0.0"
This means I needed to copy the file "hpricot_scan.bundle" (OS X uses bundles for shared libraries, on Linux that would be "hpricot_scan.so") to the following directory, creating it if necessary:
vendor/gems/hpricot-0.6/lib/i686-darwin10.0.0/
Substitute the appropriate platform name (puts RUBY_PLATFORM from irb) for your machine.
Try using Hpricot in a irb session, because i don't think this should generally happen
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'hpricot'
=> true
irb(main):003:0> doc=Hpricot.parse("<html><head><title>test</title></head><body> Wooo Hooo </body></html>")
=> # {elem {elem "test" } } {elem " Wooo Hooo " } }>
irb(main):004:0> doc.search('title')
=> # "test" }]>
irb(main):005:0> doc.search('title').text
=> "test"
That means your Hpricot is working fine. And the problem is in way you are using it in Rails. ( It would be easier if you could paste your code ).
I had few issues with Hpricot(0.8.1) earlier, had to switch back to 0.6.164 version. you can try that if you want.
HTH
Execute Below command and its works
gem install hpricot --platform=mswin32

Resources