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.
Related
I'm on Windows 10 and am a complete beginner programmer. I am using Ruby 2.4.2, Rails 5.1.4 and am following a Lynda course on how to run Rails 5 on Windows.
There's a part near the end where the tutor says to enter:
>rails db:schema:dump
to test whether you've established a connection to the MySQL by create a file inside the created project.
This is what I get when I enter the above command:
C:\Users\notmyactualuser\Documents\Sites\demo_project>rails db:schema:dump
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Users/notmyactualuser/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/notmyactualuser/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/notmyactualuser/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
The tutor doesn't address what to do with potential errors and I can't seem to find an answer. I want to build a login form using RoR and am trying to grasp the basics (clearly failing). If possible, can I get help with the above and be directed to an easy, simple, "how-to" on building a login form?
Thanks a lot.
P.S. My first post, so please go easy on me, lol.
UPDATE: So I used the command on CMD and it looks like it's successful. Can somebody point me to how to get it working with Rails?
UPDATE 2: I put in the command that Hoa requested and I got this:
ERROR: "bundle install" was called with arguments ["mysql2"]
Usage: "bundle install [OPTIONS]"
UPDATE 3: I did as Satishkakumar said and I got this:
You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.1.6.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files were retrieved from:
http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.6-win32.zip
This gem includes vendor/libmysql.dll with redistribution notice in vendor/README.
======================================================================================================
Looks like it's all sorted now? Please let me know if there's any more.
I think its issue of installing mysql2 gem in system. Follow below steps to install.
In Gemfile add the line
gem 'mysql2', '0.3.21'
And run bundle install from project folder in CMD.
bundle install mysql2
This might solve your issue. Let me know in comment section if your issue still persists.
I'm getting this error when trying to run the gem command. Does anyone know what is causing this? It's causing me to be not able to run rails g migration commands (I get a similar error), and I'd imagine probably a lot more.
Error loading RubyGems plugin "/Users/storwell/.rvm/gems/ruby-2.0.0-p247#global/gems/executable-hooks-1.2.2/lib/rubygems_plugin.rb": undefined method `stubs' for Gem::Specification:Class (NoMethodError)
/Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:255:in `matching_specs': undefined method `stubs' for Gem::Specification:Class (NoMethodError)
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:279:in `to_specs'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:309:in `to_spec'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:53:in `gem'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems.rb:572:in `load_yaml'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/config_file.rb:327:in `load_file'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/config_file.rb:196:in `initialize'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/gem_runner.rb:74:in `new'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/gem_runner.rb:39:in `run'
from /Users/storwell/.rvm/rubies/ruby-2.0.0-p247/bin/gem:21:in `<main>'
Update: I've also tried the rake command and it throws the same error.
I found an older link related to the same problem
, and it seems that it might be either a (1) Ruby installation issue, or (2) RubyGem issue. If it a Ruby issue, you need to uninstall and reinstall Ruby by using RVM (Ruby Version Manager) it seems that it worked for some. If it's (2) RubyGem issue (which it probably is), you either have to delete '/Users/storwell/.rvm/gems/ruby-2.0.0-p247#global/gems/executable-hooks-1.2.2/' folder or change the content in rubygems_plugin.rb file.
One of the users suggested (you can find from the link):
*"When I use "gem -v", the response will give me the error "Error loading RubyGems plugin "/Users/mercury/.rvm/gems/ruby-1.9.3-p194#global/gems/rubygems-bundler-0.2.8/lib/rubygems_plugin.rb": cannot load such file -- rubygems_bundler/rubygems_bundler_installer (LoadError)
So I edit "rubygems_plugins.rb", and I change the require path of rubygems_bundler, the path after modified is "./rubygems_bundler/{file_name}", and the problem solved."*
I hope these instructions + link will help you to solve the problem. I did go through the same tutorial book by Michael Hartl last summer. I think I have encountered a similar issue. I think I might have deleted one folder in order solve the issue, and perhaps reinstalled something as well (but I am not 100% because it has been a while) .
Try calling
$gem update --system
I am trying to run a Rails 2.3 app locally.
script/server gives me these errors:
bash: script/server: Permission denied
bash: parse_git_branch: command not found
script/server gives me the error:
/Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- initializer (LoadError)
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:55:in `load_initializer'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:38:in `run'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:11:in `boot!'
from /Users/stevenbrooks1111/Desktop/cssmixonline/cssweb/config/boot.rb:110:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/server:2:in `<main>'
bash: parse_git_branch: command not found
Any ideas of how I can get this to run locally?
This question is what I've been doing for the past month. I would have loved to use Rails 4, but I know better than to try it!
Install rvm or rbenv, then get into a server that correctly runs this app, and run
ruby --version
gem list > ~/myGems.txt
Using rvm or rbenv, install the exact same version of Ruby.
(Tip: whenever I say "exact same", you can fudge by bumping the revision. For example, given a gem with version 0.1.4, if it has subsequent versions 0.1.5, 0.1.6, and 0.2.0, you can bump to 0.1.6, if that will save you some grief. The revision numbers, 0.1.*, are supposed to be only bug fixes. But a minor version bump, 0.2.0, has higher odds of breaking things. I kept the same version of Ruby, but I bumped rails to 2.3.14.)
Using rvm or rbenv, install the same version of Ruby as currently runs on this app's main server.
Inside this Ruby environment (with both which ruby and ruby --version reporting the correct answers), install each gem in myGems.txt, like this:
gem install --ignore-dependencies --no-rdoc --no-ri my_gem -v=0.1.4
The --ignore-dependencies is critical, because some gems from the Pleistocene Epoch, 2009, don't specify their dependencies' versions. When some dumb 2009 gem pulls in the 2013 rake, you will be utterly screwed, because reverting that rake is really hard. And don't forget to set the -v to the same value as myGems.txt reports!
After all that, try simple rake commands like rake routes. Post any bugs you get as fresh questions, but remember to point out Rails 2.3 in the subject so nobody mis-answers with the modern fixes.
And if this app has tests or specs, getting them running should be a top priority, so you can resume TDD, leaning on the tests to allow you to make sick changes.
I have a Rails 3.2, Ruby 1.9 app that I'm attempting to setup with the bandit gem.
I've bundled installed the gem, run the bandit:install and modified the bandit.yml to (for development) values of round_robin and memory.
However, all attempts to start the dev server (rails s) result in the following error:
/Users/michaelbuckbee/Sites/bshapp/config/routes.rb:148:in `block in ': uninitialized constant Bandit::Engine (NameError)
from /Users/michaelbuckbee/.rvm/gems/ruby-1.9.3-p0#bshapp/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
from /Users/michaelbuckbee/.rvm/gems/ruby-1.9.3-p0#bshapp/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
from /Users/michaelbuckbee/.rvm/gems/ruby-1.9.3-p0#bshapp/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:260:in `draw'
from /Users/michaelbuckbee/Sites/bshapp/config/routes.rb:1:in `'
If I remove the Bandit::Engine line from the routes.rb and go into the rails console I can successfully create Bandit Experiments.
I just followed the instructions on the bandit readme and got the same error. The latest tagged version at this time is bandit-0.1.0; this is what bundler will install if you don't specify any options with gem 'bandit'. I suspect you're using the same version. Looking at the source of that version, Bandit::Engine does not exist. It does appear to be included in bandit HEAD, which is on commit 4c552c1efa at this time. Bundling from HEAD fixed the problem for me.
So, add the following in your Gemfile, bundle install, and retry your server:
gem 'bandit', :git => "git://github.com/bmuller/bandit.git"
Since I am new to rails and have learned the very basics from books I now figured that I can learn quite a bit more from reading other peoples code and trying to make sense of it so I have signed up at github and set up everything there. Now I read that one good open source project to learn from is radiant so I went to https://github.com/radiant/radiant and cloned it to a local directory. THen I proceeded as follows:
cd radiant
bundle install, which went fine
rake db:migrate, which first returned:
rake aborted! You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Using bundle exec may sol
So I typed in bundle exec rake db:migrate and recieved the following:
NOTE: Gem.source_index is deprecated, use specification. It will be removed on or after 2011-11-01. Gem.source_index called from c:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/rails/gem_dependency Rake aborted! No such file to load -- radius
So here I am wondering how to fix this problem? I also noticed that a Gemfile and a Gemfile.lock already existed in the radiant folder when it was cloned, which perhaps could be part of the problem?
Also I wonder if it is crutial that I run the same version of rails as the project is written in?
Now it should be said that I currently have rails 3.0.5 installed and run on windows
I hope someone can help me here, it has been quite frustrating since I have not been able to run any cloned github repos (radiant here just being one example).
You should edit your Gemfile and make it require newer rake.
Also you can run rake db:migrate --trace to get additional error information.
The deprecation warning is still just a warning, and it shouldn't be causing you any issues. The part of that error that is relevant is the No such file to load -- radius. You probably need to follow the instructions for installing Radiant, which include running a gem install radiant before dropping this project code somewhere.
Bundler manages installing and using the gems in your Gemfile, and if a Gemfile.lock is present it'll use those exact versions. This means you can't run Radiant with Rails 3.0.5 since the Gemfile specifies 2.3.14. Bundler will install Rails 2.3.14 and its dependencies automatically, though, so you don't need to worry about it.
By the way, this project looks like it has been very mismanaged. It's not common for a Rails project/gem to force you to actually clone it to use it. If you want to check out a Rails 3 project to learn from, I have a slim Rails 3 app that was intended to be an API up publicly on Github with some really clean code: http://github.com/coreyward/instavibe