I am trying to learn Ruby on Rails through this online tutorial
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
I'm creating an app demo_app for their second chapter.
This is what my gemfile currently looks like
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
this is what it's supposed to look like
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
group :development do
gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
I don't understand why my gemfile looks so different.
I have the updated versions of rails, ruby and gemfile.
I even ran the commands
bundle install --without production
bundle update
bundle install
and my gemfile still looks like my first snippet of code.
I've been reading through chapters 1 and 2 of this tutorial but can't figure this out. Am I supposed to edit Gemfile in the text editor? I've already tried that and I got a hundred error messages.
How do I install the gemfile so it looks like the code in the second snippet?
Please help
Let's look through the gemfile item by item (Note that any of the numbers after gems are versions and it isn't necessary that your versions match his. You can specify them if you'd feel more comfortable but unless you come to some bug that needs it, you should be fine without.)
source 'https://rubygems.org' - You both have this and this is where the gem, bundle, etc. commands in the console get your gems from for installation.
ruby '2.0.0' - He has this and you don't. What is this doing? It's specifying the version of ruby that he's using in his rails app. You can do this if you want but it won't be necessary unless you've got multiple versions of ruby installed. Perhaps you're using RVM (Ruby Version Manager) in which case this will probably be necessary. Make sure it's the version you have by using ruby -v in the console to check your version. (Output will look something like this: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0] where in the gemfile you can leave everything off besides the 2.1.1
#ruby-gemset=railstutorial_rails_4_0 - This is a comment in his gemfile for his own use. Likely he has multiple gem files and this helps him know which one to use when making the tutorial.
gem 'rails', '4.0.4' - You both have that which is just the version of rails you're using.
Next we have
group :development do
gem 'sqlite3', '1.3.8'
end
This is somewhat different than yours but how come? First of all the group :development do means that we only want to "do" (read: use) the gems in this block when we're in the development group. This one can be more clearly called an environment and can be configured/found in the config/environments/ folder. This is useful for having different gems and settings when running the rails server in development or test or production mode. He has the sqlite3 gem in the development group because he wants to use rails's default database gem for the tutorial. You will notice that you have the sqlite3 gem as well which means you can follow his tutorial successfully.
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
You have all these gems in your gemfile as well so no problems there. (They may be with different versions and with comments above them so that you know why each gem is there which is good. Rails puts the comments in by default for clarity in coding.)
group :doc do
gem 'sdoc', '0.3.20', require: false
end
Same as yours and likewise used for the docs group. It means that it won't be used unless you're specifically looking for it.
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
From person experience, I know that these are two gems that are required to deploy an app in production to heroku (a free hosting site) which you'll cover in chapter 1.4. You do not have them because you don't need them until you deploy to heroku. The production group again specifies that you want these gems for when the server runs in production (as it will on heroku). The pg gem is for postgres which is a database alternative to sqlite3 and the rails_12factor is something that enhances 12factor app handling. More can be learned here but it is only necessary to know that heroku requires it to host a rails app.
All the gems in yours that aren't in his and are commented out in yours are old rails standards that are left in because plenty of people still use them and they aren't truly phased out yet. They will not be necessary for the tutorial and you can delete them if you'd like.
Sorry it was long. Hope this helps your understanding.
It looks like your going through Hartl's tutorial, it's a great tutorial, however, if this is your first time coding and or using an MVC framework, everything is going to look like gibberish. Although this is bad practice moving forward, I suggest copying the entire gemfile that Hartl provides into your gemfile and then do a bundle install.
The point of this tutorial for beginners is to get through it with a BASIC understanding of how everything works. It's going to go over a lot of concepts that your not necessarily going to understand or use right away. The best thing to do is power through the best you can and try to finish the app. I finished it in 3 weeks and was more confused than ever, things only started to sync in once I started experimenting on my own and using the tutorial and other ruby/rails docs as a reference.
Programming is hard, and if this is your first foray into application development, I suggest having a basic understanding of Ruby first (http://www.codecademy.com/tracks/ruby) or even learning a scripting language like python (http://www.learnpython.org/). Learning python basics for some odd reason helped me understand ruby better, which made it easier to navigate and understand all the components of rails.
Anyway good luck and stick with it, there are tons of online resources to get you where you need to go. You just have to keep digging.
Related
After creating a Ruby on Rails skeleton (before pushing to master and Heroku) and running: bundle install, I sometimes encounter the following error:
An error occurred while installing pg (0.18.2), and Bundler cannot continue
Make sure that gem install pg -v '0.18.2' succeeds before bundling.
The following command remediates the issue altogether: bundle install --without production.
Why exactly does the aforementioned command remediate the issue? As I understand, the command bypasses production environment gems for deployment; so, is my understanding correct and why must this be the case? Thank you!
Here is my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
The best resource answering the "why" component of this question appears to be explained thusly by Michael Hartl's Ruby on Rails Tutorial:
"Heroku uses the PostgreSQL database...which means that we need to add the pg gem in the production environment to allow Rails to talk to Postgres...Generally speaking, it's a good idea for the development and production environments to match each other as closely as possible, which includes using the same database, however we'll use SQLite locally and PostgreSQL in production."
So, basically it appears that the issue is a matter of maintaining conventions between two different environments- production and development (local)- and more specifically, database types (Postgres vs SQLite), which is why bundle install --without production is required:
"To prepare the system for deployment to production, we run bundle install with a special flag to prevent the local installation of any production gems (which in this case consist of ph and rails_12factor)...Because the only gems added are restricted to a production environment, right now this command doesn't actually install any additional local gems, but it's needed to update Gemfile.lock with the pg and rails_12factor gems."
If the remediation for Heroku deployment bundle install --without production is an acceptable alternative to bundle install, it just seems too bad to be true; if so, is there another setting or file I can revise in order to achieve the same results effected by the regular bundle install? Thanks!
I added the Better Errors gem to my gemfile like as seen in my gemfile below, and ran bundle and saw Using better_errors 1.1.0 and restarted my server several times. I watched the railscast episode on how to install it. I’ve never had a problem installing any other gem in the past (I'm new to programming). I read the documentation and I already checked for this:
Note: If you discover that Better Errors isn't working - particularly after upgrading from version 0.5.0 or less - be sure to set config.consider_all_requests_local = true in config/environments/development.rb.
Any ideas on how to get this gem working would be much appreciated! Here is my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
end
# Use sqlite3 as the database for Active Record
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
gem 'better_errors'
end
gem 'bootstrap-sass', '~> 3.1.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
With Vagrant, add this to your app's config/environments/development.rb (anywhere inside the configure block):
BetterErrors::Middleware.allow_ip! "0.0.0.0/0"
Then restart your server.
(This is just a slight variation on Sasha's solution.)
DO NOT add this to your production environment!
Valerie -- are you on a virtual machine? Better errors can sometimes not work well with VMs.
The solution I've found is this:
First, in your app's config/environments/development.rb (anywhere inside the configure do), add:
BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
Then you need to define that environment variable. Find your remote IP by firing up a browser, hitting the old error page (just throw a raise in a controller or something), and finding the "REMOTE_ADDR" in the error page's "Show env dump" section. Then copy that IP and set it as an ENV variable (in your .env or application.yml file, or wherever you keep those).
Note -- DO NOT add that to production. It's unnecessary at best (Better Errors should only be run/included in development -- as you've ensured above).
Then restart your server. Any chance that fixes it?
in addition for all better you need to add this to your config/environments/development.rb:
BetterErrors::Middleware.allow_ip! "TRUSTED_IP"
where "trusted_ip" is "REMOTE_ADDR" in default error page
for me it's 10.0.2.2
In the file app/config/environments/development.rb do you have this line present in the code ?
# Show full error reports and disable caching.
config.consider_all_requests_local = true
I am running vagrant, rails 5 and ruby 2.3 and I added the below to my config/environments/development.rb and got it working.
# Allow usage of better_errors on Vagrant
BetterErrors::Middleware.allow_ip! "10.0.2.2"
# Show full error reports and disable caching.
config.consider_all_requests_local = true
Same answers as above but just wanted to confirm it for anyone running the rails 5 beta.
Old question but in case this can help anyone. I just ran into the same issue running this on my localhost: Better errors was installed and configured but I received no helpful errors.
Issue was easily solved by running bundle update.
This updated Using better_errors 2.9.1 (was 2.4.0) and now I get better errors.
So in my quest to get a ruby dev environment working, I've ran into an issue that seems...confusing to this ruby noob.
When executing rails server, it starts up as expected, but when you put in localhost:3000 to your standard web browser, it replies the following:
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile.
Now here's the confusing part. I have sqlite3 installed (the 64 bit version, as that is what I downloaded, and am running a 64 bit OS), as verified by gem query (here's the full list of gems)
Uninstalling and reisntalling didn't do a lick of good for the issue at hand, but it did install without a hitch. Also the gemfile for the project that I'm testing this with is the folliwing
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
As you can see, sqlite3 is specified in the Gemfile quite early on, yet for whatever reason when I try to load the main page, it acts like it's not there.
Particulars for this machine are the following that weren't mentioned earlier in the gems section:
Rails 4
Ruby 2
Windows 7
Anyone ever ran into this before?
I just had this issue too. Go into your Gemfile.lock file and search for the 'sqlite3' entry. You'll note it reads sqlite3 (1.3.8-x86-mingw32).
Change that to sqlite3 (1.3.8-x64-mingw32) and then run the bundle install command and everything should work like normal.
I faced same issue and this seems to be Windows 7 specific Env issue. My problem was resolved with below changes
Go into your Gemfile.lock file and update sqlite3 (1.3.8-x86-mingw32) to sqlite3 (1.3.8-x64-mingw32)
Run bundle install from the project directory. That will update Gemfile.lock. You also have to restart the Rails server.
Also see config/database.yml which specifies which gem to use for the database.
development:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
Firstly, Im a big fan of sphinx search. Thanks to sphinx.
Now my question is,
We are ready with a rails 3.1 app which uses sphinx search for full text searching.
Now, I know heroku is the best when it comes to rails hosting. It does not have support
for sphinxsearch, I hear.
If any of you know the right place to host a rails 3.1 app with sphinx search please
guide me.
I will mention the other things that Im using in my rails 3.1 app as listed in my gem
file.
#############################################################
source ' http://rubygems.org '
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'execjs'
gem 'therubyracer'
gem 'thinking-sphinx', '2.0.10'
gem "gritter", "1.0.1"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails'
gem 'client_side_validations'
gem "bcrypt-ruby", :require => "bcrypt"
#############################################################
Thank you so much.
Actually, Heroku does support Sphinx through the Flying Sphinx add-on. Otherwise, any decent VPS should work for you. Linode, in particular, has a pretty good reputation.
I'd like to now if anybody could help me with my heroku deployement.
I've set up my Rails 3.2 app with the following Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'mongoid'
gem 'bson_ext'
gem 'mongoid_slug'
gem 'heroku'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem "compass", ">= 0.12.alpha"
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
And I have run the rails g mongoid:config command
From the heroku support, I've added the mongolab extension and changed the mongoid.yml evironnement variables to MONGOLAB_URI
When I then deploy the app, it doesn't run on heroku.
I'm not sure what is going on, but i get this error message in the Heroku logs:
WARNING: Invalid .gemspec format in '/app/.bundle/gems/ruby/1.9.1/specifications/actionmailer-3.2.0.gemspec'
2012-01-29T19:13:46+00:00 app[web.1]: Could not find activemodel-3.2.0 in any of the sources
here is the full log file:
https://gist.github.com/1700231
has anybody experienced the same issue? I'm not sure if the problem comes from my set up or if I need to add something to rails to work with mongoid?
Cheers.
It's been a bit of pain int the b*tt, but I'm finally there.
http://railsapps.github.com/rails-heroku-tutorial.html
is the right place to go to deplay rails 3.2 on heroku.
This said my head hurt, not too much fun to get so many hurdles when one wants to learn.
Octopress looks fine at the moment I tell you :)
Alright let's keep going