MultiJson AdapterError Rails 4 Ruby 2 Passenger - ruby-on-rails

I am trying to setup rails on aws (Dev env work fine). Can not get production to start up correctly. Can shell in and db looks good. I looked into my log file and I am getting the following error.
rake aborted!
MultiJson::AdapterError: Did not recognize your adapter specification (cannot load such file -- json/ext/parser).
Have MultiJson and Json gems installed and in the gemlock file.
This happens during asset compilation.

I'm not 100% sure what the problem was but I read somewhere that downgrading the multi_json gem to version 1.7.8 would fix this and it did for me. Please note that this is just what fixed my app, it might not be the same for you but hopefully it is! I did the following:
Add the following to your Gemfile:
gem 'multi_json', '1.7.8'
And then update the gem:
bundle update multi_json
Commit the new changes:
git add .
git commit -m "Downgrade multi_json gem"
And push to AWS:
git aws.push
That should resolve the issues.
If you get a complaint from bundler about mis-matched dependencies you can re-install your gems and hopefully fix the dependency issues by removing the Gemfile.lock.
To delete the Gemfile.lock run:
rm Gemfile.lock
And then run bundle install:
bundle install
Commit again and push to aws.

After dealing with a situation where I couldn't revert the version, I found another solution to the problem.
We are just missing the appropriate dependent gem. This worked for me to fix it without downgrading:
gem install json
Hopefully that also helps other people with this problem. I got here from Google, so hopefully other people will as well.

I'm having a similar problem today. Here's a bit of my log:
Started POST "/users/sign_in" for 173.228.60.113 at 2015-09-29 15:53:47 +0000
MultiJson::AdapterError (Did not recognize your adapter specification (cannot load such file -- json/ext/parser).):
activesupport (3.2.3) lib/active_support/dependencies.rb:251:in `require'
activesupport (3.2.3) lib/active_support/dependencies.rb:251:in `block in require'
activesupport (3.2.3) lib/active_support/dependencies.rb:236:in `load_dependency'
activesupport (3.2.3) lib/active_support/dependencies.rb:251:in `require'
json (1.8.3) lib/json/ext.rb:13:in `'
json (1.8.3) lib/json/ext.rb:12:in `'
json (1.8.3) lib/json/ext.rb:9:in `'
bundle show (on the ec2 instance) shows where the json gem is installed:
[ec2-user#ip-172-31-43-145 current]$ bundle show json
/usr/local/share/gems1.9/gems/json-1.8.3
Below that directory there is a file ext/json/ext/parser/parser.so
This is a native extension. I've run into issues with these not installing correctly many times before. My workaround is to install a symlink in lib/json/ext
The command looks like this:
ln -s ../../../ext/json/ext/parser/parser.so .
from the above directory.
I also put in a symlink for generator.so. The command, executed while connected to lib/json/ext was:
ln -s ../../../ext/json/ext/generator/generator.so .
There's another directory under ext/json called fbuffer, but it only has a .h file, no .so.
This resolved the issue. I knew where to look because the error message always tells you a path relative to the core gem .rb file, which in this case was ext/json/json.rb
I am not at all happy about having to do this by hand each time a gem with a native extension updates. I would very much like it if someone could tell me how to not have to do that. But in the meantime, this will fix it.

Related

How to fix "can't find executable rails for gem railties. railties is not currently included in the bundle"?

My application server is not starting and giving the error when I am trying to start the server by:
bundle exec rails server -b 0.0.0.0
Traceback (most recent call last):
4: from /root/workspace/abl-rest-client_ruby/local/ruby/2.6.0/bin/ruby_executable_hooks:24:in `<main>'
3: from /root/workspace/abl-rest-client_ruby/local/ruby/2.6.0/bin/ruby_executable_hooks:24:in `eval'
2: from /usr/local/rvm/gems/ruby-2.6.3/bin/rails:23:in `<main>'
1: from /usr/local/rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:480:in `block in replace_bin_path'
/usr/local/rvm/gems/ruby-2.6.3/gems/bundler-2.0.2/lib/bundler/rubygems_integration.rb:460:in
`block in replace_bin_path': can't find executable rails for gem railties. railties is not
currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
I just started working on rails yesterday, so I am too new to the entire concept.
I understand the error that I am missing the railties gem but I am unable to add it.
I have tried uninstalling gems, removing gems, re-installing those, etc. as per the answers to this question 'https://stackoverflow.com/questions/9212116/rails-could-not-find-railties'
but nothing helped.
My gem list has the railties version 6.1.0 but my vendor/cache doesn't have it. I am using windows for the development and I am inside a docker container.
I don't know if not having the railties in my vendor/cache is the problem or I am missing something else.
I have already tried a couple of solutions like specifying my ruby version to rvm
rvm use -myrubyversion, re-starting bundler a couple of times, etc.
Any suggestions?
Make sure your terminal is in the root of the application and not the folder above it. That is, after you run rails new application_name_here enter cd application_name_here to get to the right folder.

Using forked (and patched) Rails 2-3-stable from git woes

Everything started when we needed to apply this patch - http://seclists.org/oss-sec/2012/q2/504 to our app. The seemingly simple task turned up to be a pain in the *ss.
I knew I had the following options:
1.Monkeypatch;
2.Vendor rails;
3.fork Rails, apply the patch for 2.3 to the 2-3-stable
branch and use it in the Gemfile.
Option #3 looked the most attractive to me, because it would allow me to rebase with the official repo, if needed; apply additional changes in a clean way - no need to clob the app repository with dozens of source files from Rails' gems (like vendoring would do). Monkey patching might have done the job, since the 2.3-stable branch is not being updated that often, but I don't really like opening classes for patches like this.
So I proceeded with #3.
1. I forked Rails;
2. I cloned my Rails repo locally;
3. I applied the 2.3 patch (http://seclists.org/oss-sec/2012/q2/att-504/2-3-sql-injection.patch)
using git am --signoff;
4. I pushed the changes.
5. I went to our app's Gemfile and added:
gem "rails","2.3.14", :git => "git://github.com/fullofcaffeine/rails.git", :branch => "2-3-stable"
6. Ran bundle install
Everything looked great, as bundle install finished successfully. When I tried to start the Rails server, I've got a "no such file to load --initializer" error.
After a bit of googling, I found the following post - How to use a branch in a fork of rails in a project with bundler. I did exactly as he said, creating the gemspecs manually, and changed the Gemfile accordingly. When I tried to run bundler, surprisingly enough it ran without issues, and I saw this in the output:
Using activerecord (2.3.14) from git://github.com/fullofcaffeine/rails.git (at 2-3-stable) Successfully built RubyGem
Name: activerecord
Version: 2.3.14
File: activerecord-2.3.14.gem
Using rails (2.3.14) from git://github.com/fullofcaffeine/rails.git (at 2-3-stable) Successfully built RubyGem
Name: rails
Version: 2.3.14
File: rails-2.3.14.gem
...
and so on, for each of the gems I created a gemspec for.
However, when I try to run the Rails server, I get this:
$ script/server
/Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/source.rb:572:in `load_spec_files': git://github.com/fullofcaffeine/rails.git (at 2-3-stable) is not checked out. Please run `bundle install` (Bundler::GitError)
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/source.rb:385:in `local_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/source.rb:555:in `specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:356:in `converge_locked_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:345:in `each'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:345:in `converge_locked_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:143:in `resolve'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:90:in `specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:135:in `specs_for'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/definition.rb:124:in `requested_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/environment.rb:23:in `requested_specs'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler/runtime.rb:11:in `setup'
from /Users/fullofcaffeine/.rvm/gems/ruby-1.8.7-p357#myapp/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
from ./script/../config/../config/preinitializer.rb:16
from ./script/../config/boot.rb:28:in `load'
from ./script/../config/boot.rb:28:in `preinitialize'
from ./script/../config/boot.rb:10:in `boot!'
from ./script/../config/boot.rb:125
from script/server:3:in `require'
from script/server:3
Also, if I try to find the gems that Bundler built (the message I pasted above about Bundler building the gems), I can't find them.
I'm really not sure what to do, such a simple task turned into a nightmare. I might just monkeypatch the classes if this find out I'm spending too much time on this.
So the question really is - What is the most pragmatic solution for this "I need to patch or customize Rails to my needs" scenario?
EDIT: I solved the issue by monkeypatching for now, see my last comment below.
So, I solved the patch issue by MonekyPatching ActiveRecord::Base. I reverted the changes to the Gemfile, I'm using Rails 2.3.14 from Rubygems.org now and not from my git fork, and I created an initializer in config/initializers, and pasted the following code: pastie.org/4087875. Now, the application is using the fixed method from the patch (seclists.org/oss-sec/2012/q2/att-504/2-3-sql-injection.patch). However, I'd still like to know why the fork approach did not work, so if someone could shed some light, I'd be grateful.

Installing a forked github gem of Toto

Ok, this is probably simple, but I'm having a bit of a pain trying to get it to work.
So I was using the gem "Toto", which I installed using "sudo gem install toto", but I recently found a fork of the gem I would rather use here https://github.com/evaryont/toto.
I tried specifying the gem url with --source, but I guess github doesn't support gems anymore aside from "the list". I then tried downloading the forked source and running "rake build" and "rake install" which seemed to create a gem just fine, but when I plug it back into the same application which comes with the gem, it fails to load.
It dies like this.
computer:myblog User$ thin start -R config.ru
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- toto (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from config.ru:2
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `initialize'
from config.ru:1:in `new'
from config.ru:1
Sample Toto Application
git clone git://github.com/cloudhead/dorothy.git myblog
I'm also a little discouraged about building the gem like this because I'm hosting on Heroku, and I would like to make sure that I can use this gem on there as well. I suppose I may have to unpack this gem and commit it to my source?
Update
I also tried using bundler with the following in my Gemfile, and I get the same error, would this mean its just an incompatibility in the sample code and the forked gem?
gem "toto", :git => "git://github.com/evaryont/toto.git"
Are you running in a context where the gem exists? Bundler handles :git-installed gems by cloning the source and storing it in a special directory for bundled gems. It's not actually installed to your system, and won't run unless bundler is running first.
Try this:
bundle exec thin start -R config.ru

error sqlite3 requires Ruby version >= 1.9.1

I've used sqlite before. My friend sent me a skeleton rails app that I am trying to run.
When I try to do "rails server" or "thin start" it says
Could not find sqlite3-0.1.1 in any of the sources"
I tried to do bundle install but it throws this error:
Installing sqlite3 (0.1.1) /Library/Ruby/Site/1.8/rubygems/installer.rb:364:in ensure_required_ruby_version_met': sqlite3 requires Ruby version >= 1.9.1. (Gem::InstallError)
from /Library/Ruby/Site/1.8/rubygems/installer.rb:135:ininstall'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/source.rb:96:in install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/installer.rb:55:inrun'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:ineach'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/installer.rb:44:in run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/installer.rb:8:ininstall'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/cli.rb:225:in install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:insend'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:in run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/vendor/thor/invocation.rb:118:ininvoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/vendor/thor.rb:246:in dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/lib/bundler/vendor/thor/base.rb:389:instart'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.12/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19
I don't know why it's trying to look in the 1.8 folder with Ruby 1.9.2 installed.
What am I doing wrong?
Your bundle command is pointing to your system Ruby, type the following to see which Ruby your Bundler is pointed to: head -1 $(which bundle) Either that needs to be pointed at the Ruby you want to use and/or you need to use the Ruby you want to use to install the Bundler gem (which will put the right shebang line in your bundle executable).

Ruby on Rails issue..mainly dealing with ruby gems/bundler

I was trying to use rspec and for some reason it wasn't working. I think it lacked some dependencies or something. Everything else in Ruby 1.9 was working perfectly on my laptop though. So I did a ruby gems system update (sudo gem update --system). I then did a gem update (sudo gem update). When I tried to run or create apps in rails I get the below listed error message: I also get this same message when I try to do gem update, gem install, gem clean, etc. I am confused. I even tried to update bundler to the latest version but I still get this same error message. I hope someone can help. Thanks.
demetrius-fords-macbook-pro-17:~ demet8$ gem check
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-0.8.1/lib/rubygems_plugin.rb:2:in require': no such file to load -- bundler/commands/bundle_command (LoadError)
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-0.8.1/lib/rubygems_plugin.rb:2:in'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1113:in load'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1113:inblock in '
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1105:in each'
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1105:in'
from :225:in require'
from <internal:gem_prelude>:225:inload_full_rubygems_library'
from :324:in const_missing'
from /usr/local/bin/gem:12:in'
Your backtrace indicates that you're running Bundler 0.8.1. Please uninstall it and make sure you have a more recent version of bundler installed :)

Resources