user3410606
user3410606

Reputation: 1

ERROR Errno::ECONNABORTED: An established connection was aborted by the software in your

I'm trying to send a post request by jQuery to Rails controller this is the post request:

 $(document).ready(
    function() {
        $("#LogIn").submit(function() {
            var myemail = $('input[name=Email]').val();
            var mypassword = $('input[name=Password]').val();
            var myObj = {
                "user": {
                    "email": myemail,
                    "password": mypassword
                }
            };
            $.ajax({
                url: "localhost:3000/user/HendelLogIn",
                type: "POST",
                data: myObj,
                dataType: "application/json"
                success: function(data) {
                    alert(data);
                }
            });
        });
    }
);

</script>

as you can see the post request is to the following address: localhost:3000/user/HendelLogIn

This is the HendelLogIn method:

 def HendelLogIn
   email    = params[:user][:email]
   password = params[:user][:password]
  @User    = User.authenticate(email, password)
  if @User 
    redirect_to :controller => "user", :action => "profile", :id => @User.id
 end

and as you can see this action redirect_to the following action:

 def profile
   @User = User.find(params[:id])
   if @User
   respond_to do |format|
   format.json {render :json => @User }
   end
   end
 end

that renders back Json response to the jQuery post, but in this process I am having the following error in rails console:

Redirected to localhost:3000/user/1/profile
Completed 302 Found in 140ms (ActiveRecord: 1.0ms)
[2014-09-02 14:12:03] ERROR Errno::ECONNABORTED: An established connection was aborted by the    software in your

host machine.

    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `write'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `<<'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `_write_data'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:368:in `send_body_string'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:249:in `send_body'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:152:in `send_response'
    c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:110:in `run'
    c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Upvotes: 0

Views: 1611

Answers (1)

Bhavnesh
Bhavnesh

Reputation: 461

there could be problem with your javascript and stylesheet tags.

Remove all the tags from header section in application.html.erb .

Hope so this will solve your problem .

Upvotes: 0

Related Questions