2015-07-10 138 views
-1

我剛配置Mongoid對於Rails項目,跑rails g mongoid:config編輯我mongoid.yml要像下面。蒙戈::錯誤:: NoServerAvailable

development: 
    clients: 
    default: 
     database: abacus_development 
     # Provides the hosts the default client can connect to. Must be an array 
     # of host:port pairs. (required) 
     hosts: 
     - localhost 
     options: 

test: 
    clients: 
    default: 
     database: abacus_test 
     hosts: 
     - localhost 
     options: 
     read: 
      mode: primary 
     max_pool_size: 1 

再接着想一切運行良好,腳手架一個叫Activity控制器和模型。隨着我跑rails s。該應用程序在localhost:3000運行良好,但現在我得到localhost:3000/activites它吐出這一點。

ActionView::Template::Error (No server is available matching preference: #<Mongo::ServerSelector::Primary:0x007fbda47c4110 @tag_sets=[], @options={:database=>:abacus_development}, @server_selection_timeout=30>): 
     15: </thead> 
     16: 
     17: <tbody> 
     18:  <% @activities.each do |activity| %> 
     19:  <tr> 
     20:   <td><%= activity.amount %></td> 
     21:   <td><%= activity.indicator %></td> app/views/activities/index.html.erb:18:in `_app_views_activities_index_html_erb___73038992978597028_70226242222820' 

任何想法?

回答

1

您正在運行蒙戈好嗎?如果你在Mac或'sudo service mongod start',可能與'mongod'有關。可能是一個愚蠢的答案,但你永遠不知道

+0

是啊,我。但是'sudo service mongod start'不適用於我。我使用'沖泡安裝mongodb'但似乎有可能是與一個問題,因爲我甚至不能做'mongo'或'mongod'沒有它沒有安裝MongoDB的。 – Souljacker

+0

如果你只運行'mongod',你得到的錯誤是什麼? –

+0

我解決了它。我沒有在我的計算機上正確配置MongoDB,並且沒有設置啓動代理,因此每次需要使用它時,都需要同時執行'mongod'和'mongo'。 – Souljacker

0

蒙戈通過默認端口27017運行,試圖改變你的主機配置爲localhost:27017在您的mongoid.yml。