0

1) I have installed MongoDB (Windows 7 64bit). Created "data/db" path and started mongod via cmd.

2) I have created Rails project by using RubiMine 7. I have added two lines for my Gemfile:

gem 'mongoid'
gem 'bson_ext'

Then I made bundle install.

3) I have run rails generator for mongoid:config, this added to me mongoid.yml file in my config folder.

4) Created scaffold with string and text attributes. This game me that kind of model:

class Article
    include Mongoid::Document
    field :name, type: String
    field :content, type: String
end

Then I launched my server. When I open my localhost:3000/articles url it gives me TypeError no implicit conversion of nil into String error.

I don't understand what I did wrong? I'am using last versions of ruby, rails, mongodb and mongoid.

My logs:

Started GET "/articles" for 127.0.0.1 at 2015-02-28 14:30:29 +0600
Processing by ArticlesController#index as HTML
Rendered articles/index.html.erb within layouts/application (3.0ms)
Completed 500 Internal Server Error in 16ms

ActionView::Template::Error (no implicit conversion of nil into String):
12:   </thead>
13: 
14:   <tbody>
15:     <% @articles.each do |article| %>
16:       <tr>
17:         <td><%= article.name %></td>
18:         <td><%= article.content %></td>
app/views/articles/index.html.erb:15:in
Rendered D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-     2.0.0/lib/action_dispatch/templates/rescues/_source.erb (3.0ms)
Rendered D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_trace.html.erb (5.0ms)
Rendered D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_web_console.html.erb (1.0ms)
Rendered D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/template_error.html.erb within   rescues/layout (28.0ms)

UPDATE:

I launched rails console and started typing commands myself:

a = Article.new
a.title = "AAAA"
a.content = "BBBB"
a.save

This throwed me that kind of error:

TypeError: no implicit conversion of nil into String
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:190:in `open'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:190:in `block in  lazy_initialize'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:186:in `synchronize'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:186:in `lazy_initialize'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:237:in `each_address'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:115:in `block in each_address'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:114:in `each'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:114:in `each_address'
from D:/Ruby21-x64/lib/ruby/2.1.0/resolv.rb:57:in `each_address'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/moped-2.0.4/lib/moped/address.rb:51:in `block in resolve'
from D:/Ruby21-x64/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
from D:/Ruby21-x64/lib/ruby/2.1.0/timeout.rb:35:in `block in catch'
from D:/Ruby21-x64/lib/ruby/2.1.0/timeout.rb:35:in `catch'
from D:/Ruby21-x64/lib/ruby/2.1.0/timeout.rb:35:in `catch'
from D:/Ruby21-x64/lib/ruby/2.1.0/timeout.rb:106:in `timeout'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/moped-2.0.4/lib/moped/address.rb:50:in `resolve'
... 25 levels...
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/mongoid-4.0.2/lib/mongoid/interceptable.rb:138:in `run_callbacks'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/mongoid-4.0.2/lib/mongoid/persistable/creatable.rb:116:in `prepare_insert'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/mongoid-4.0.2/lib/mongoid/persistable/creatable.rb:23:in `insert'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/mongoid-4.0.2/lib/mongoid/persistable/savable.rb:23:in `save'
from (irb):15
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from D:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from D:/Phantasy star/Mobi/Daniars_Project/Svadba/mongo_id_test/bin/rails:4:in `require'
from D:/Phantasy star/Mobi/Daniars_Project/Svadba/mongo_id_test/bin/rails:4:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

It is throwing SAME ERROR even by using only rails console.

4
  • I have recreated my project by using rails new project_name --skip-active-record command, added gems mentioned above, when I try to open page of my scaffolds it throws me no implicit conversion of nil into String error again. Is it BUG of mongoid or something else? Commented Feb 28, 2015 at 9:54
  • Run Rails console (rails c), then run your code to receive your articles and provide full backtrace of your problem. Backtrace provided above display only part of useful information i.e. position of problem in view, but not the root of problem. Commented Feb 28, 2015 at 10:54
  • Does version number of my ruby (2.1), version of my Rails (4), version of mongo (2.6) affect to mongoid?? Commented Feb 28, 2015 at 10:54
  • When I run rails generator and try to do with my Articles like create, save or get first, It will throw that error. Commented Feb 28, 2015 at 13:23

1 Answer 1

1

Your latest backtrace show that your don't specify host address of MongoDB. Read this section about configuration Mongoid gem.

Update

Maybe your mongoid.yml has incorrect format.

Update 2

Run the following commands in irb console and provide output:

$  ~  irb
2.1.0 :001 > require 'resolv'
 => true
2.1.0 :002 > Resolv::Hosts::DefaultFileName
 => "/etc/hosts"

Seems like you doesn't have hosts file in windows or it has incorrect format. If you have it provide it content too.

Sign up to request clarification or add additional context in comments.

7 Comments

I have generated mongoid.yml by using this command: rails g mongoid:config, it says identical. My mongod is running on 27017 port and in mongoid.yml there is in hosts: is written - localhost:27017. Still TypeError: no implicit conversion of nil into String error when I try to open view of scaffold or try to use save first create destroy commands by rails console.
Look at Update 2.
It gave me nil value. What do I need to do. I think we are very close.
Look at this and this code. As you can see it read path to directory where should be hosts file from Windows Registry. Can you onen SYSTEM\CurrentControlSet\Services\Tcpip\Parameters node in registry.exe and check key DataBasePath. If it is doesn't exists try to create it (as string) and specify any correct directory path. Then create empty hosts file in this directory.
I have DataBasePath file in this directory where value is %SystemRoot%\System32\drivers\etc, but there is no hosts file. What kind of type must hosts file be and what is coorect name Hosts or hosts it must have?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.