How to add dependency to gemfile.lock through gemspec? - ruby-on-rails

Personnel in relation to add_runtime_dependency, add_dependency and add_development_dependency the "Gem Specification", I'm trying to understand them. How they work and how to differentiate them.
When I used the add_development_dependency, I was unable to observe anything different. When I used the add_dependency and also the add_runtime_dependency, the same effect was observed.
It was added to gemfile.lock as the only dependence of my gem, but not a project dependency. And I would like it to be added as a project dependency, because I think add redundant as a unit of my gem, and dependence of the project, adding it to the Gemfile.
What I do not understand is that if I add the jquery as a unit of my gem, but don't add it directly in the application Gemfile, it is not found. I get the following error.
"could not find file 'jquery'".

You should not gemfile.lock manually. You should include jquery-rails in Gemfile and do bundle install. gemfile.lock is managed by bundler. If you need dependencies only in a given environment you can do something like.
group :development do
gem 'better_errors'
gem 'bullet'
gem 'lol_dba'
gem 'meta_request'
gem 'pry-rails'
gem 'rbeautify'
gem 'rsense'
gem 'rubocop'
gem 'spring'
gem 'ruby-growl'
end
group :development, :test do
gem 'binding_of_caller'
gem 'jazz_hands'
end
Anything not in a specific group will be included in all environments.

Related

"Attaching" a gem to Rails to prevent "require" everywhere?

The name of a gem is not the same as the module. Right now I need to require it and include in various types of files, such as controllers and models. This is amounting to many requires which I don't have to do for other gems. It's a gem I can update. Is there a way the gem needs to be configured so it is "attached" to Rails, and if so, where may I find instructions to do this?
UPDATE: using required: "name-of-module" in Gemfile removes need for require everywhere. Still wondering, if gem could be configured to not require this in Gemfile?
In the Gemfile, you can do these things:
# Require a different file than the gem's name
gem 'foo', require: 'bar'
# Install but not require anything.
# You need to manually require the gem somewhere.
gem 'foo', require: false
You can still add version and platform specification if you want.
Real-world examples are ActiveSupport and rspec:
gem 'activesupport', '~> 5.2', require: 'active_support/all'
gem 'rspec', '~> 3.1', group: :test, require: false
You need to specify which files you want Ruby to load for you, so you either need specify the gem in your Gemfile (and run bundle exec ...) or put require in the right place(s) in your code. There's no way around that.
If it's a gem that you work on at the same time as you use it in another project, then you can specify a path to the gem. Like
# Gemfile
source "https://rubygems.org"
ruby '2.6.1'
gem 'my_gem', path: '/home/user/Development/my_gem'
This way, you can change your gem and use it directly without having to build and install it.

Ruby on Rails installed on windows getting ExecJS::ProgramError

I'm working on a project which I normally work on Mac OSX. I'm on ruby MRI V.1.9.3-p194 and rails v.3.2.8.
but, for the time being, there has been a need to collaborate the project source code with another team member who's using windows.
I proceeded on to set up everything on my colleague's windows machine and almost everything seems to work quite well, the same ruby and rails framework version are used. I managed to get 'bundle install' to pass by having most of their dependencies resolved. (So, you can imagine that the versions of gems have got updated from those on my Mac Machine)
I also have node.js installed on my colleague's machine in order to make ruby able to run javascript.
A while later, it seemed I was able to start the web server using "bundle exec thin start" and it's starting without any error. The other reason, I'm quite sure my setup's been coming in the right way
because I can retrieve model records via rail console beautifully. But I'm only getting one error, every time I try to browse to the app on the web browser.
Every time I'm getting node.js dependency error "cannot find module 'stylus'"
that even prevents me from getting the login page loaded.
here is a snapshot of the error I get:
also, I'm happy to share you my Gemfile, so it could give you more clues what actually goes wrong? it can be found below:
source 'http://rubygems.org'
gem 'rails', '3.2.8'
gem 'rubyzip', '< 1.0.0'
gem 'roo','1.12.1'
gem 'mysql2', '0.3.11'
gem 'jquery-rails', '2.1.2'
gem 'haml', '3.1.7'
gem 'thin', '1.4.1'
group :development do
gem 'capistrano', '2.13.4'
end
gem 'devise', '2.1.2'
gem 'devise-async', '0.5.0'
gem 'cancan', '1.6.8'
gem 'simple_form', '2.0.4'
gem 'cocoon', '1.1.1'
gem 'inherited_resources', '1.3.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'mechanize', '2.5.1'
gem 'delayed_job', '3.0.4'
gem 'paperclip', '3.4.0'
gem 'spreadsheet', '0.6.4.1'
gem 'geocoder', '1.1.6'
gem 'whenever', '0.8.2'
gem 'american_date', '1.0.0'
gem 'money','5.1.1'
gem 'rets','0.5.1'
gem 'haversine','0.3.0'
gem 'capybara'
gem 'poltergeist'
gem 'selenium-webdriver'
gem 'redis'
gem 'execjs','2.0.0'
group :assets do
gem 'stylus', '0.7.1'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.3.0'
end
What should I do to get this to work? Any help would be greatly appreciated.
Updated:
I updated my question rgrd Brad suggestion accordingly.
I've performed as suggested. but when I have node.js uninstalled, I rather got another error like below "The node.js runtime is not available". any idea?
You can see the answer here
I changed from coffee-script-source 1.12.2 to 1.8.0 in Gemfile.lock file.
ex) coffee-script-source (1.8.0)
And then, in cmd, I put a command like 'bundle install'.
If you do not have a bundle, you can install bundle such as
gem install bundle
Finally, turn off your rails server and turn on again.
Thank you.

Rails tutorial 3.6, 'bin' is not recognized as an internal or external command

I'm stuck at section 3.6 of railstutorial.org, specifically when I run
> bin/rspec spec/
on my Windows 7 machine I get 'bin' is not recognized as an internal or external command.
I have already typed
> bundle --binstubs
I don't have RVM on here. Should I install it?
When I go cd bin and execute rspec, I get
'load': cannot load such file
My gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :test do
gem 'capybara', '1.1.2'
end
group :production do
gem 'pg', '0.12.2'
end
Thank you in advance.
Just thought I'd reiterate the author's warning about this section:
"This section should only be attempted by fairly advanced users and
can be skipped without loss of continuity. Among other things, this
material is likely to go out of date faster than the rest of the
tutorial, so you shouldn’t expect everything on your system to match
the examples exactly, and you may have to Google around to get
everything to work."
As a side note... I originally tried to use ruby on rails on a windows machine but I found that much of the support community used apple or linux boxes. I have been much happier since I started dual-booting into Ubuntu. The transition was easier than I expected and I have had fewer issues with gems.

Help with Ruby on Rails Gem file and bundle install

I am trying to learn rails from http://ruby.railstutorial.org/
Exercise 3 explains to install rspec, rspec-rails, and webrat using this gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'sqlite3', '1.3.3', :require => 'sqlite3'
group :development do
gem "rspec-rails", ">= 2.0.1"
end
group :test do
gem "rspec-rails", ">= 2.0.1"
gem 'rpsec'
gem 'webrat'
end
i have tried to install rspec-rails and webrat and they seem to have installed correctly.
C:\RubyProject\sample_app>gem install rspec-rails -v=2.0.1
**************************************************
Thank you for installing rspec-rails-2.0.1!
This version of rspec-rails only works with versions of rails >= 3.0.0
To configure your app to use rspec-rails, add a declaration to your Gemfile.
If you are using Bundler's grouping feature in your Gemfile, be sure to include
rspec-rails in the :development group as well as the :test group so that you
can access its generators and rake tasks.
group :development, :test do
gem "rspec-rails", ">= 2.0.1"
end
Be sure to run the following command in each of your Rails apps if you're
upgrading:
script/rails generate rspec:install
Even if you've run it before, this ensures that you have the latest updates
to spec/spec_helper.rb and any other support files.
Beta versions of rspec-rails-2 installed files that are no longer being used,
so please remove these files if you have them:
lib/tasks/rspec.rake
config/initializers/rspec_generator.rb
Lastly, be sure to look at Upgrade.markdown to see what might have changed
since the last release.
**************************************************
Successfully installed rspec-rails-2.0.1
1 gem installed
Installing ri documentation for rspec-rails-2.0.1...
Installing RDoc documentation for rspec-rails-2.0.1...
But when i run bundle install
I get the following error message
Could not find gem 'rpec-rails (= 2.0.1)' in any of the gem sources listed in your Gemfile.
So me being a total newbie to RoR has no idea why this is occurring. I have tried following this link
http://railsforum.com/viewtopic.php?id=41464
which seems to be a dead end. I'm hoping that someone here can point me in the right direction. Any help would be appreciated.
If your output is correct:
Could not find gem 'rpec-rails (= 2.0.1)' in any of the gem sources listed in your Gemfile.
Then it looks like you've got a typo in your gem file. You've installed the gem, but it won't bundle with the app since you didn't spell rspec-rails correctly. Check your declarations in the gem file.
It is an annoying word to spell.
I noticed your :test group contains a typo: rpsec instead of rspec.

Launching RoR server for an existing app gives error

I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.

Resources