Can't create a database in Ruby on Rails - ruby-on-rails

I'm following some tutorials of association in rails database, the first step is to create the app with rails new newProject -B. Then i create the two models with rails g scaffold Father name:string and rails g scaffold Child name:string sex:string father:references.
After that i try to create the database with the command rake db:create, but an error appears:
Could not find nokogiri-1.6.7.1 in any of the sources Run bundle
install to install missing gems.
I run the command bundle install normally, but when i tried again, the same error appears.
I tried to insert in the GemFile gem 'nokogiri', '~> 1.6', '>= 1.6.7.1' and the same error persists.

I had a similar issue with nokogiri a couple of months ago.
I solved it by adding '-rc3' to the end of the gem version, like this:
gem "nokogiri", ">= 1.6.7.rc3"

I've had this problem a few times before, you can try installing the gem manually using gem install nokigiri

Have you try
$bundle update
?
Can you post the error logs to see if it is a Permissions Error or something else?

Related

Rails: ArgumentError in UsersController#create wrong number of arguments (2 for 1)

I generated scaffold User with attributes name:string and email:string. After fulfilling the form in the browser and hitting Create User, following error occurs:
click
Any clue about what might have gone wrong?
This happens when using an older version of turbolinks gem.
Try updating the gem to the latest version.
Add the following to your Gemfile:
gem 'turbolinks', '~> 2.5.3'
Then, do:
bundle install
Then, restart the rails server and try again!

Trying to install survey Gem

I am following these guides:-
http://www.runtime-revolution.com/runtime/blog/introducing-survey
When I try:-
gem "survey", "~> 0.1"
as it suggests I get:-
ERROR: While executing gem ... <RuntimeError>
Unknown command survey,
When I try:-
gem install survey
It says that everything has installed fine but when I try:-
Rails generate survey plain namespace:contests
or
rails generate survey:install
I get :-
Could not find generator
Also, looking in my Gemfile survey is not in there?
gem "survey", "~> 0.1"
Is not a command. This is the line you need to manually add to your Rails Gemfile to list the gem as dependency in your Rails application, as also explained in the README you linked.
After you add it, run
$ bundle
and the gem will be installed in your Rails application.
As a side note, you may also benefit from reading some introductory book about using Ruby and Rails.

Implemented Rails 3, but "rails -v" is still 2.3.10?

I can see the rails 3 gem from gem list. But why the rails -v still tell 2.3.10? What should I do to update it?
In your Gemfile for your project, just specify :
gem 'rails', '3.0.3'
And you are good to go :)
If you have multiple versions of rails showin in gem list, you can call a specific one by passing the version as the first argument:
$ rails _2.3.5_

annotate command not working, added it to my gemfile

My gem file looks like:
group :development, :test do
gem 'rspec-rails'
gem 'annotate-models', '1.0.4'
end
I ran 'bundle install' and it installed the annotate-models bundle.
If I type: annotate I get a command not found error.
If I type: bundle show annotate I get a 'could not find gem annotate in the current bundle.
If I type bundle show annotate-models it says it installed in:
/Library/Ruby/Gems/1.8/gems/annotate-models-1.0.4
typing:
annotate-models
doesn't work either.
I'm following along in railstutorial.org and got stuck at this point.
Edit: Better version (using Bundler to install it only for the current project)
Add gem 'annotate' to Gemfile
Run $ bundle install
Run $ bundle exec annotate
Edit2: Seems you have to explicitly specify annotate version for now, so in Gemfile put gem 'annotate', '2.4.1.beta1' (which is a prereleased beta gem that works with the latest version of activerecord as opposed to specifying the github repo directly)
Edit3: 2.5.0 final is out now, so hopefully no need to force a beta version any more, just getting the latest should work!
Old version (with installing the gem on a system level too):
If running Rails 3 the drill is:
Run $ sudo gem install annotate
Add gem 'annotate' to Gemfile
Run $ bundle install
Run $ annotate
Be happy :)
You should run the command inside your bundled environment with:
$ bundle exec annotate
Check out the man page for more details.
The most voted answer didn't fully work for me, as I was getting and additional error when follow the proposed solution:
undefined method `namespace' for main:Object (NoMethodError)
I'm including below what worked for me (I'm using Ruby 1.9.2 and Rails 3.1.3 under Ubuntu 11.10):
Install annotate
$ gem install annotate
Modify Gemfile adding the following line
gem 'annotate',
:git => 'git://github.com/jeremyolliver/annotate_models.git',
:branch => 'rake_compatibility'
Install bundle
$ bundle install
Now you can use annotate as follows:
$ bundle exec annotate
I'm new to this, but I was having this problem doing the rails tutorial, but by adding the gems bin path to the PATH env variable I was able to fix it. (Just like gertas said a few posts above)
First in the command prompt:
gem list -d annotate
and you'll get a result that says something like
: annotate-models (1.0.4)
Author: Dave Thomas
Rubyforge: http://rubyforge.org/projects/annotate-models
Homepage: h'ttp://annotate-models.rubyforge.org
Installed at: C:/ruby192/lib/ruby/gems/1.9.1
the key line is:
Installed at: C:/ruby192/lib/ruby/gems/1.9.1
So in this case add a /bin to that path, For example I used: C:\ruby192\lib\ruby\gems\1.9.1\bin is what you want to add to your PATH environment variable.
To change your PATH environment variable on Vista do the following go to: control panel >> system >> advanced system settings(link on the left). Once the box opens up,click the Advanced tab and then the Environment variables button. Then on the system variables find the PATH variable and click the Edit button. Since paths are separated by semi-colons, add
;C:\ruby192\lib\ruby\gems\1.9.1\bin
At the end of the variable value field.
It should look like
`some/path;some_other_path;C:\ruby192\lib\ruby\gems\1.9.1\bin`
when you finish
Save it, and close and reopen the command prompt. annotate and rspec started to work for me after that. Good luck.
For me the answer was this one:
http://news.railstutorial.org/model-annotation
Use
gem 'annotate', '2.4.0'
instead of
gem 'annotate-models', '1.0.4'
It looks like the gem name was changed at RubyGems.org.
I think your PATH env variable lacks path to gems bin directory.
I guess it should be: /Library/Ruby/Gems/1.8/bin
You can use it for Rails 4, add gem in your gem file gem "annotate", "~> 2.5.0" and run following command
rails g annotate_models:install
instead of
rails g annotate:install
Then run following command to add schema information after model class
bundle exec annotate -p after
or can use following for before
bundle exec annotate -p before
If bundle exec annotate doesn't work, try:
rake annotate_models

Couldn't find 'rspec' generator

I'm trying to install RSpec as a gem after having it installed as a plugin. I've gone ahead and followed the directions found here http://github.com/dchelimsky/rspec-rails/wikis for the section titled rspec and rspec-rails gems. When I run ruby script/generate rspec, I get the error Couldn't find 'rspec' generator. Do only the plugins work? If so, why do they even offer the gems for rspec and rspec-rails? I'm running a frozen copy of Rails 2.1.2, and the version of rpsec and rspec-rails I'm using is the newest for today (Nov 7, 2008) 1.1.11.
EDIT Nov 12, 2008
I have both the rspec and rspec-rails gems installed. I've unpacked the gems into the vender/gems folder. Both are version 1.1.11.
Since RSpec has been become the default testing framework in Rails you no longer need to create spec docs via the rspec generators:
Rails 2 RSpec generator
rails generate rspec_model mymodel
Rails 3 RSpec generator
With RSpec as the default testing framework simply use Rails' own generators. This will construct all of the files you need including the RSpec tests. e.g.
$rails generate model mymodel
invoke active_record
create db/migrate/20110531144454_create_mymodels.rb
create app/models/mymodel.rb
invoke rspec
create spec/models/mymodel_spec.rb
Have you installed both rspec and rspec-rails gems?
script/generate rspec
requires rspec-rails gem to be installed.
For Rails 3 and rspec 2+
You must make sure you include 'rspec' and rspec-rails' in your Gemfile
Run Bundle Install
then run rails g rspec:install
If you are using rails 2.3 You need to use
ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.3.3'
and then
ruby script/generate rspec
Is there supposed to be an 'rspec' generator? I've only used the following:
script/generate rspec_model mymodel
script/generate rspec_controller mycontroller
I've had this problem before, it boiled down to the version of RSpec I had not working with the version of Rails I was using. IIRC it was a 2.1 Rails and the updated RSpec hadn't been released as a gem. In fact, 1.1.11 is the gem I have, which would be the latest available (ignoring github gems), so I'm pretty sure that's exactly what my problem was.
I've taken to just using the head of master rspec with whatever version of Rails I happen to be on, it seems stable to me (and isn't going to break things in production, unless somehow a test broke with a false positive).
I do it with git using submodules, for example:
git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec_on_rails
In case anyone is wondering about Rails 3 now,
this seems to do the trick for me:
http://github.com/rspec/rspec-rails/blob/29817932b99fc45adaa93c3f75d503c69aafcaef/README.markdown
I'm using rails 2.3.9. I started of trying to use the gem(s) but just couldn't get the generator for rspec to show up. Then I installed the plugin(s) using the instructions on https://github.com/dchelimsky/rspec/wiki/rails and that did the trick.
On Fedora 9 (OLPC) I did:
$ sudo gem install rspec
$ sudo gem install rspec-rails
Those got me to where I could run
$ ruby script/generate rspec
This worked for me, whereas the git instructions did not work.
If you are using bundler version 1.0.8 you should $ gem update bundler to a newer version 1.0.9.
I had the same symptons and updating bundler helped me out.
Now $ rails g is using gems defined in the Gemfile. Also I grouped my gems like this:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :test, :development do
gem 'capybara', '0.4.1.1'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'rspec-rails', '~> 2.4'
gem 'launchy'
end
(Note that test gems are also in the :development group.)
Have a nice day :)
Lukas
If you type script/rails generate, the only RSpec generator you'll actually see is rspec:install. That's because RSpec is registered with Rails as the test framework, so whenever you generate application components like models, controllers, etc, RSpec specs are generated instead of Test::Unit tests.
Please note that the generators are there to help you get started, but they are no substitute for writing your own examples, and they are only guaranteed to work out of the box for the default scenario (ActiveRecord & Webrat).
https://github.com/rspec/rspec-rails
You might need to run bundle exec :
bundle exec rails g rspec:install
You'll need to do
sudo gem install cucumber-rails

Resources