Why does Rails demo app give "uninitialized constant ExecJS::RubyRacerRuntime::Context::V8"? - ruby

Being new to Rails, I'm trying to get a basic "hello world" app up and running. Specifically the app in chapter 2 of Agile Web Development with Rails. Loading up the hello world page results in the error given in the title.
So far I've done the following:
rails new demo
cd demo
Added gem 'therubyracer' to the Gemfile after ExecJS complained about no JavaScript runtime being available.
bundle install
rake about # (see below)
rails generate controller Say hello goodbye
rails server
At this point WEBrick fires up and I load up http://localhost:3000/say/hello. WEBrick logs the following error (which also appears in the browser):
Started GET "/say/hello" for 127.0.0.1 at 2012-10-26 11:45:10 -0400
Connecting to database specified by database.yml
Processing by SayController#hello as HTML
Rendered say/hello.html.erb within layouts/application (80.9ms)
Completed 500 Internal Server Error in 167ms
ActionView::Template::Error (uninitialized constant ExecJS::RubyRacerRuntime::Context::V8
(in /home/error/work/demo/app/assets/javascripts/say.js.coffee)):
3: <head>
4: <title>Demo</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___1746644185114933585_70069037653480'
Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.7ms)
Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.2ms)
Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (18.7ms)
[2012-10-26 11:45:12] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
rake about returns:
About your application's environment
Ruby version 1.9.3 (x86_64-linux)
RubyGems version 1.8.24
Rack version 1.4
Rails version 3.2.8
JavaScript Runtime therubyracer (V8)
Active Record version 3.2.8
Action Pack version 3.2.8
Active Resource version 3.2.8
Action Mailer version 3.2.8
Active Support version 3.2.8
Middleware ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x0000000276b298>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root /home/error/work/demo
Environment development
Database adapter sqlite3
Database schema version 0
The workstation is running Fedora 17 x86_64. Despite that, I've pretty much ignored the ruby gems in the yum repositories (I think) and used gem install in my home directory to get everything I need. (Again, I think.)
Being new to Ruby and Rails, I'm pretty sure I've missed some obvious convention that I'm not yet aware of. I'm also not quite sure what additional information I might need to provide, so please let me know that as well.

Please try this:
sudo apt-get install nodejs
rubytheracer and nodejs are both javascript libraries. Most folks are going for nodejs these days.

Related

gemset rails folder empty

I am using ruby 1.9.3-p551 with rvm and try to install rails 3.2.17 with bundler. After bundle install and bundle show rails I see an empty rails folder. Is this normal? I am wondering why I can still start my rails server.
After starting the server I get 500 page error.
I think I've found out how it works.
So the rails-folder is empty, but a lot of other dependencies are installed, like railties, actionpack, active record and so on.
And the bin/rails calls the railties which again calls active record and so on.

uninitialized constant Moped::BSON in rails 4 app on heroku

I just updated from rails 3 to rails 4. Everything works locally, but deployed on heroku, I get the following error:
ActionView::Template::Error (uninitialized constant Moped::BSON):
3: %nav.navbar-collapse
4: %ul.nav
5: %li
6: - if user_signed_in?
7: = link_to 'Logout', destroy_user_session_path, :method=>'delete'
8: - else
9: = link_to 'Login', new_user_session_path
app/views/layouts/_navigation.html.haml:6:in `_app_views_layouts__navigation_html_haml___1118031947301940708_70104067139880'
app/views/layouts/application.html.haml:18:in `_app_views_layouts_application_html_haml__1093647294459268715_70104069850820'
The same error occurs in other haml files when I access current_user
- if current_user
...
The following worked for me:
add to Gemfile:
gem "bson"
gem "moped", github: "mongoid/moped"
bundle install
add to application.rb:
require "bson"
require "moped"
Moped::BSON = BSON
Answer from:
https://github.com/mongoid/mongoid/issues/3455
See this comment from Moped's author as of Moped 2.0.0 (which is the version , as of this writing, used as the driver in mongoid 4.0.0):
Moped's BSON implementation has been removed in favor of the 10gen bson gem 2.0 and higher. All Moped::BSON references should be changed to just BSON.
https://github.com/mongoid/moped/blob/master/CHANGELOG.md
This error can also be caused by having references to Moped::BSON in serialized cookies/session. Deleting cookies fixes it then.

Ruby on rails application fails to run on one machine but runs on another (same setup)

I have problem with moving Ruby on Rails app between two machines,
Both of them have exactly the same OS and setup (Arch linux x86_64 updated today),
(well, this can not be true, because this problem happens, but I'm unable to spot any differences at the moment)
both have rails in version 3.2.12 and ruby 1.9.3
On my laptop everything works fine, app runs correctly,
on desktop command
rake assets:precompile
fails with error:
/usr/bin/ruby /usr/bin/rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
rake aborted!
couldn't find file 'jquery'
(...)
I have this in my application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
and gem 'jquery-rails' in my Gemfile (bundle install completes successfully)
but this is probably irrelevant - rake fails in exactly same wqay without this gem installed.
I tried running rails server, webpage shows error:
cannot load such file -- sass
(in [path])
Problem must lay somewhere in my ruby/rails installation on desktop, app source is kept in git, both machines have the same revision with clean working dir - tmp is in .gitignore.
Asset pipeline is enabled in config/application.rb
I tried the following:
Deleted tmp directory
Reinstalled rails, jquery and couple of other gems
Used other environments (rake fails in all of them)
Downloaded jquery and put it in assets dir (this is supposed to be automatic in rails),
i this case rake assets:precompile fails on sass stylesheet compilation (I have sass-rails installed!)
I must be missing something obvious here, anyone had this problem before?
Do I need to purge my ruby installation or is there a simpler way to solve this?
(ps. Sorry about my poor English)

Ruby on Rails view

I am new in ruby on rails. I was trying to check some code. I copied all folders of an existing project from my friends and pasted them to a newly created project at my machine. And also changed the config file. It shows following error:
*Template is missing
Missing template movies/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "../Software Engineering for Software as a Service/Software/Project/rottenpotatoes/app/views"*
Some one suggested me that it is because haml is not installed, i installed haml by "gem install haml" but it still shows the same message. Can any one help me?
If rails had access to the HAML gem it would show HAML as a handler in that error. Your error does not. It's possible you need to restart your rails server.
You should be using the Gemfile for managing gems, though. Add gem 'haml' to your Gemfile. Go to your console and cd to the application directory. Run bundler to install the gems with the bundle command. Restart your rails server.

Could not find rack-cache-1.0.3 in any of the sources

I have created a very basic Rails 3.1 app, deployed to a box that runs Ruby 1.8.7 (P334) (I can't easily go to 1.9.2. there unfortunately).
After deploying and running 'bundle install' I tried to run a console:
bundle exec rails console
And I get:
Could not find rack-cache-1.0.3 in any of the sources
and the console does not come up.
It seems that this particular version of rack-cache is listed as a dependency by ActionPack 3.1.0.
Can someone explain to me what I need to do to resolve this, i.e. get bundler to attach this version of rack-cache to the project?
Also I read that bundler stores the project-specific GEMs 'somewhere else', i.e. no longer in the global Ruby GEM path. Is there a default location for this project specific place ?
Oh and I also keep getting heaps of 'invalid gemspec' warnings with Rails 3.1, i.e.:
Invalid gemspec in [/usr/local/lib/ruby/gems/1.8/specifications/rack-cache-1.0.3.gemspec]: invalid date format in specification: "2011-08-27 00:00:00.000000000Z"
Ran into this issue when upgrading my Rails 3.0 app to 3.1.
Edit the /usr/local/lib/ruby/gems/1.8/specifications/rack-cache-1.0.3.gemspec file and set s.date = %q{2011-08-27}. This will fix your problem.

Resources