4

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

UsersController#create 中的 Errno::ECONNREFUSED

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
4

1 回答 1

9

您的数据库连接很好,事实上,您的错误消息中有答案;)

如果您查看它,您会发现该代码:

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

这意味着您需要启动您的 solr 服务器。你可以从 simple 开始RAILS_ENV=your_env rake sunspot:solr:run。还可以考虑添加一些begin... rescue@user.save来输出一些消息,而不是让整个应用程序崩溃。

如果您对为什么在没有显式调用 solr 的情况下得到该错误感兴趣 - solr 会向save方法添加回调,因此它会索引每个新(或更新的)记录,这意味着您不会(理论上)在添加新数据后从头开始重新索引.

于 2013-09-03T21:02:52.140 回答