用户控件#creore中的Errno :: ECONNREFUSED

时间:2013-09-03 19:04:13

标签: ruby-on-rails controllers sunspot-rails sunspot-solr

我的申请已经开始,所以我继续注册。输入我的信息后,我收到一个错误页面说:

Errno ::在UsersController中创建ECONNREFUS#创建

Connection refused - {:data=>"<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">User 1</field><field name=\"type\">User</field><field name=\"type\">ActiveRecord::Base</field><field name=\"class_name\">User</field><field name=\"username_text\">mikeadeleke</field><field name=\"bio_text\">Founder of Edopter</field></doc></add>", :headers=>{"Content-Type"=>"text/xml"}, :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :path=>"update", :uri=>#<URI::HTTP:0x007fb6c3c911d0 URL:http://localhost:8982/solr/update?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}

消息:

app/controllers/users_controller.rb:14:in `create'

所以这是我的代码导致了阻塞。我看到没有问题,并通过roodi验证器运行它。

class UsersController < ApplicationController
    before_filter :get_user, except: [:new, :create]

    def get_user
        @user = User.find_by_username(params[:user_name])
    end

    def new
        @user = User.new
    end

    def create
        @user = User.new(params[:user])
        if @user.save
            sign_in @user
            flash[:success] = "Woohoo! Thanks for creating an account. Feel free to edit your profile or look around elsewhere!"
            redirect_to(user_url(@user.username))
        else
            render 'new'
        end
    end

    def show
        @resources_upvoted = []
        @user.upvotes.where(upvotable_type: "Resource").each do |upvote|
            @resources_upvoted << upvote.upvotable
        end
        @crafts_interested = []
        @resources_upvoted.each do |resource|
            craft = resource.craft
            if !@crafts_interested.include?(craft)
                @crafts_interested << craft
            end
        end
    end

    def edit
        if @user != current_user
            redirect_to user_url(@user.username)
        end
    end

    def update
        @user.email = params[:email]
        @user.bio = params[:bio]
        @user.save

        redirect_to edit_user_url(params[:user_name])
    end

    def destroy
        @user.destroy

        redirect_to home_url
    end
end

1 个答案:

答案 0 :(得分:9)

您的数据库连接没问题,事实上,您已在错误消息中回答;)

如果你看一下,你会发现代码:

URL:http://localhost:8982/solr/update?wt=ruby>

这意味着您需要启动solr服务器。您可以使用简单RAILS_ENV=your_env rake sunspot:solr:run启动它。考虑在begin... rescue周围添加一些@user.save块来输出一些消息,而不是让整个应用程序崩溃。

如果你有兴趣为什么在没有显式调用solr的情况下得到该错误 - solr会将回调添加到save方法,因此它会对每个新的(或更新的)记录进行索引,这意味着你赢了&#39; t(在理论上)在添加新数据后从头开始重新索引。