Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno::ECONNREFUSED in UsersController#create

My application is up so then I proceeded to register. After I input my information I receive an error page saying:

Errno::ECONNREFUSED in UsersController#create

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}

The message:

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

So here is my code that is causing the hold up. I see no issues and ran it through the roodi validator.

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
like image 789
Mike Adeleke Avatar asked Jan 12 '23 11:01

Mike Adeleke


1 Answers

Your db connection is fine, in fact, you have answer in your error message ;)

If you will look at it you will find that code:

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

which means you need to start your solr server. You may start it with simple RAILS_ENV=your_env rake sunspot:solr:run. Consider also adding some begin... rescue block around @user.save for outputting some message rather than letting whole app crash.

If you're interested why you get that error without an explicit call to solr - solr adds callback to save method, so it indexes every new (or updated) record which means you won't have (theoretically) reindex from scratch after adding new data.

like image 142
zrl3dx Avatar answered Jan 22 '23 13:01

zrl3dx