Ruby on Rails Gemfile error - ruby-on-rails

I'm new to web developing and doing a self study guide to learn (the odin project). I'm just now getting to the installation of all the different tools I'll need for programming but having an issue. When setting up ruby on rails for Heroku deployment I'm getting a syntax error. I'm following a guide, http://goo.gl/v2LcbU and when I try to do step 7.2 (bundle install --without production) I get a syntax error. I run ruby -c Gemfile and the error says Gemfile:37: syntax error, unexpected keyword_do, expecting $end.
I've tried a few things but I'm confused and not sure what it's trying to say is wrong with line 37. If you look at the guide I linked it had be replace some of the Gemfile and this is what my Gemfile looks like that is causing an error and not allowing me to bundle install --without production.
Gemfile
http://i.imgur.com/IIjvhwM.png
I'm linking an image of it because I'm not sure how to link the file correctly yet, sorry.
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
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
# 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 invalid:
group
:doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group is a method being called, :doc is an argument and the do...end block is, well, a block. In Ruby, the first method argument needs to immediately follow the method name. Your group should look more like this:
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

you can see other sample by running rails standard command, like this:
rails new apptest
it will automatically generate many files, include Gemfile, at bottom of that, you will see something like this:
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'rspec-rails'
gem 'capybara'
end
study from this, add your own gem, enjoy rails:)

Related

pg::error error relations users already exists

I am trying to deploy my app to heroku. Everything works fine until I try to run "heroku run rake db:migrate". Then I get the following error (please open this image in new tab to see better:
I ran rake db:drop, rake db:create, and rake db:migrate locally. Then I pushed it to heroku and tried running "heroku run rake db:migrate" again, but same error. I know this has something to with the schema already having user table, but I don't see it on my files.
Gem file:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/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
# for users
gem 'devise', '~> 4.2'
# Use ActiveModel has_secure_password
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
# Use Unicorn as the app server
# gem 'unicorn'
gem 'tzinfo-data'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :test do
# for seeing test covarage
gem 'simplecov', :require => false
end
group :development do
# 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'
gem 'sqlite3'
end
# upload files
gem 'carrierwave', '~> 1.0'
# bootstraps
gem 'bootstrap-sass', '~> 3.3.4.1'
# Material Icons
gem 'material_icons'
# Material css
gem 'materialize-sass'
group :production do
gem 'pg', '0.15'
gem 'rails_12factor'
end
Is there something else I have to do or am I missing something?
That means your table "users" already exists on heroku. Do you really want to delete all tables on heroku ? If so, you have you can do
heroku pg:reset DATABASE
https://devcenter.heroku.com/articles/heroku-postgresql#pg-reset
If you only want to make some changes on your tables you should really work with migrations like
add_column :users, :my_attribute, ...
removeColumn :users, :my_attribute_to_remove
PS: To drop, create, migrate the db locally will not have any effects at the db on heroku.

try using the bin/bundle install command

This is my gem file
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3’, group: [:development, :test]
# gems required by Heroku
gem ‘pg’, group: :production
gem ‘rails_12factor’, group: :production
# 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/rails/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 :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
This is the error i get when trying to use the bin/bundle install command
LJ$ bin/bundle install --without production
[!] There was an error parsing `Gemfile`: syntax error, unexpected tIDENTIFIER, expecting end-of-input - gem 'sass-rails', ‘~> 5.0’
^. Bundler cannot continue.
# from /Users/LJ/code/blog/Gemfile:12
# -------------------------------------------
# # Use SCSS for stylesheets
> gem 'sass-rails', ‘~> 5.0’
# # Use Uglifier as compressor for JavaScript assets
# -------------------------------------------
**I can't figure out what the problem is. I am going along with the Rails Crash Course book if that helps.
An example of the invalid quote characters is:
gem 'sqlite3’
The second ' is an invalid single quote. Notice how it slightly curves in your sample code.
These types of errors usually show up when you edit the text in a text editor like TextEdit. Try fixing the single quotes using a different text editor. Try using something like TextWrangler, SublimeText, or just nano.

Ruby on Rails-Cucumber - error: Could not find generator cucumber:install

I'm new to RoR and Cucumber. I've installed RoR and Cucumber and am stepping through the Cucumber Backgrounder (https://github.com/cucumber/cucumber/wiki/Cucumber-Backgrounder)
When I get to this step: run "rails generate cucumber:install" I receive the error: Could not find generator cucumber:install
I reviewed a very similar issue relative to JRuby:
Jruby and Cucumber / Cucumber Rails - Could not find generator cucumber:install
I've tried all of the suggestions there (to the best of my ability) and still get the error message. (setting GEM_HOME and GEM_PATH variables, modifying Gemfile, etc.)
My Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# 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', '~> 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
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
# added by SC to get cucumber to install
group :test do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
gem 'database_cleaner'
end
When I run bundle install I notice that cucumber and cucumber-rails are not in the list.
I managed to install both locally, but that didn't resolve the issue.
Any suggestions are appreciated.
you need add in you GemFile in the group of :development, :test
gem 'cucumber-rails', '~> 1.4.2', :require => false
Next use:
rails g cucumber:install
And that's it

Onemonth Rails tutorial gemfile won't let me bundle install

I'm doing the one month rails tutorial, coming across small issues I can't seem to fix. I couldn't get some of the bootstrap features to work for making edits on this simple site, so thinking it was a problem with the gem being not updated, I went to the bootstrap site and i tried to update a gem which it said was [gem 'bootstrap-sass', '~> 3.1.1'] so
In my gem file I went from just having
gem 'bootstrap-sass'
to
gem 'bootstrap-sass', '~> 3.1.1'
also noticed the tutorial had this code in the gem file
group :doc do
#bundle exec rake doc:rails generates the API under doc/api
gem 'sdoc', require: false
end
so I added that as well,
bundle installed, restarted rails server
that didn't fix the problem so tried going back to what was before and got an error below..
You cannot specify the same gem twice with different version requirements.
You specified: sdoc (~> 0.4.0) and sdoc (>= 0)
heres what my gem file looks like now, I am trying to bundle install and push to heroku but this error message won't let me.
GEM FILE below
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3' #it told me i had 2 versions so i commented out for now
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# 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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background.
Read
more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'bootstrap-sass', '~> 3.1.1'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :doc do
# bundle exec rake doc:rails generates the API under doc/api
gem 'sdoc', require: false
end
Should I just read the Rails book from Hartl for a better understanding under the hood?
You have specified gem 'sdoc' twice in your Gemfile with different versions which is causing the error:
You cannot specify the same gem twice with different version requirements.
You specified: sdoc (~> 0.4.0) and sdoc (>= 0)
See below:
source 'https://rubygems.org'
##...
##...
gem 'sdoc', '~> 0.4.0', group: :doc ##<-- First
##...
##...
group :doc do
# bundle exec rake doc:rails generates the API under doc/api
gem 'sdoc', require: false ##<-- Second
end
Remove the one which is not required and run bundle install

Could not find generator 'devise:install' unless using sudo rails generate devise:install

I have a rails app that I am trying to install devise on.
I use the command
rails generate devise:install
but it fails, giving this message:
Could not find generator 'devise:install'. Maybe you meant 'ckeditor:install', 'assets' or 'comment'
however if I use sudo rails generate devise:install it works.
I do not want to generate devise:install as root however.
I have done chmod a+x on the directory.
I also recently changed macbooks and imported my ssh key from the previous macbook, but I added the key with ssh-add. Not sure if this is the problem.
this is my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
gem 'thin'
# Use sqlite3 as the database for Active Record
gem 'pg'
# 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/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'devise', '3.5.3'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
gem 'bootstrap_form'
gem 'kaminari'
gem 'carrierwave'
gem "rmagick", :require => 'RMagick'
gem 'ckeditor'
gem 'acts_as_commentable'
gem 'addressable'
gem 'vimeo'
gem 'underscore-rails'
gem 'gmaps4rails'
gem 'geocoder'
# 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 :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'pry'
# 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
gem 'rails_12factor', group: :production
I managed to solve this by deleting my Gemfile.lock, doing bundle install again and then stopping spring with spring stop I could then call the generator without root privileges
It's kind of weird, but I solve the problem restarting my mac

Resources