Printing of dates from database (MongoDB)

Hello there,
I’m trying to make a simple script for statement dates from MongoDB,
but unfortunately, so far without the success result.

My Gemfile looks follow:

require ‘rubygems’
require ‘mongo’
source ‘http://rubygems.org
gem ‘rails’, ‘3.0.5’
gem “mongo_mapper”
gem “rails3-generators”

in config/initializers/mongo.rb:

MongoMapper.connection = Mongo::Connection.new(‘localhost’, 27017)
MongoMapper.database = “justatest-development”

if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect_to_master if forked
end
end

Controller (test_controller.rb):

class TestController < ApplicationController
def index
@xxx=Test.all
end
end

Model (test.rb)

class Test
include MongoMapper::Document

key :name
end

and View (index.html.erb)

Test#index

Find me in app/views/test/index.html.erb

  • <%=ttest.name%>
  • <%end%>

in a MongoDB is following record:

{ “_id” : ObjectId(“4d715abad3d8493475000003”), “name” : “John S.” }

I don’t know, what I missed, where is a bug or what is wrong… I
studied it a whole afternoon, but I can’t to get the result into my view
(index.html.erb)… Can me someone help with this, please?

Million times, thank you!

On Mar 5, 8:34pm, Manny 777 [email protected] wrote:

in a MongoDB is following record:

{ “_id” : ObjectId(“4d715abad3d8493475000003”), “name” : “John S.” }

I don’t know, what I missed, where is a bug or what is wrong… I
studied it a whole afternoon, but I can’t to get the result into my view
(index.html.erb)… Can me something help with this, please?

So what happens? Does Test.all return the record in question?

Fred

Hi Fred,
Test.all should return this one record, but in my script nothing.

This part of code:

<[email protected] do |ttest|%>

  • <%=ttest.name%>
  • <%end%>

    Does not list any record… and I am trying to find, why… thanks

    So I heard a million of tutorials and still nothing. Everything I’ve the
    right set up, but the printing dates from collection I can’t to get…
    For example, my setup is the same as here
    (http://blog.futureshock-ed.com/2010/07/mongomapper-with-rails-3.html),
    data in my database are saved (I see that via console), but through the
    script is not possible to show that…

    No message, no error, nothing…

    Do you everybody some idea, what would be wrong? It makes me crazy…

    Thanks for whatever ideas or hints!

    Frederick C. wrote in post #985716:

    On Mar 6, 1:45am, Manny 777 [email protected] wrote:
    So at the rails console, what does Test.all returns? is your record
    actually in the right database/collection?

    Fred

    Hmm…maybe here could be the problem, because I don’t know, how to
    specific collection, from which I want to showing dates…

    Current situation:

    controller

    class TestController < ApplicationController
    def index
    @tests=Testt.all
    end
    end

    model

    class Testt
    include MongoMapper::Document
    key :name, String
    end

    mongo.rb

    MongoMapper.database = “mydb”

    And the dates are stored in “mydb” database in a collection called
    “people”. And if I see on my code, I am not see the setup of collection
    “people”, where are stored dates… So the problem could be perhaps
    here… but in tutorials I am not see specific the collection, from they
    show data…

    Or the names of models, controllers and the collections must be the
    same?

    On Mar 6, 11:01am, Manny 777 [email protected] wrote:

    Or the names of models, controllers and the collections must be the
    same?

    If the model is called Testt then mongomapper will assume that the
    collection is called testt (although I’m sure there is a way to
    override that), much like how activerecord derives the table name from
    the class name
    If you renamed your class to Person, mongomapper should use the people
    collection automatically. Controller name is unimportant

    Fred

    On Mar 6, 1:45am, Manny 777 [email protected] wrote:

    So I heard a million of tutorials and still nothing. Everything I’ve the
    right set up, but the printing dates from collection I can’t to get…
    For example, my setup is the same as here
    (http://blog.futureshock-ed.com/2010/07/mongomapper-with-rails-3.html),
    data in my database are saved (I see that via console), but through the
    script is not possible to show that…

    So at the rails console, what does Test.all returns? is your record
    actually in the right database/collection?

    Fred

    Thanks Fred, you’re my hero! Now it works :slight_smile:

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs