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.
rails new project_name --skip-active-recordcommand, 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?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.