Rails Internal Server Error Ajax
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you completed 500 internal server error rails might have Meta Discuss the workings and policies of this site
Ruby Completed 500 Internal Server Error
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or rails post 500 internal server error posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
500 Internal Server Error Ruby On Rails
6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why does my rails AJAX request throw internal server error? up vote 0 down vote favorite I have a table , where each line has a link <%= link_to 'Delete', [lesson.group, lesson], remote: true,method: :delete%> I ajax 500 internal server error want the link to destroy the corresponding db entry and remove the corresponding line from the table without reloading the page. The action is def destroy @lesson = @group.lessons.find(params[:id]) @lesson.destroy respond_to do |format| if @lesson format.html { redirect_to edit_group_path(@group), notice:'Succesfully deleted lesson' } format.js {} else format.html { redirect_to edit_group_path(@group), notice:'Error!' } end end end The entries get removed, but I can only see the change when I reload the page, and the console throws DELETE http://localhost:3000/groups/1/lessons/14 500 (Internal Server Error) Extract from the log: Started DELETE "/groups/1/lessons/18" for 127.0.0.1 at 2013-10-24 18:39:22 +0400 Processing by LessonsController#destroy as JS Parameters: {"group_id"=>"1", "id"=>"18"} [1m[36mGroup Load (1.0ms)[0m [1mSELECT "groups".* FROM "groups" WHERE "groups"."id" = ? LIMIT 1[0m [["id", "1"]] [1m[35mLesson Load (1.0ms)[0m SELECT "lessons".* FROM "lessons" WHERE "lessons"."group_id" = 1 AND "lessons"."id" = ? LIMIT 1 [["id", "18"]] [1m[36m (0.0ms)[0m [1mbegin transaction[0m [1m[35mSQL (4.0ms)[0m DELETE FROM "lessons" WHERE "lessons"."id" = ? [["id", 18]] [1m[36m (10.0ms)[0m [1mcommit transaction[0m Completed 500 Internal Server Error in
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Rails Ajax Form
Overflow the company Business Learn more about hiring developers or posting ads with us
500 Internal Server Error Ajax Post
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ajax call causes internal server error 500 rails controller up vote 1 down vote favorite http://stackoverflow.com/questions/19568667/why-does-my-rails-ajax-request-throw-internal-server-error I use ruby on rails mvc and I'm trying to use an ajax call to send some data back to the server side. I'm confused about how ajax requests are issued and processed in the mvc. ---------------- in my javascript file------------------ $.ajax({ type: 'POST', url: 'http://localhost:3000/locations', data: { lat: position.coords.latitude, lng: position.coords.longitude }, contentType: 'application/json', dataType: 'json' }); I'm using a respond_to block to catch this request in my controller: ---------------- http://stackoverflow.com/questions/18305514/ajax-call-causes-internal-server-error-500-rails-controller in my home controller ------------------ respond_to do |format| format.js { render 'users/locations' } format.html {} end ---------------- route.rb ------------------------ post 'users/locations' get 'users/locations' match "/locations", to: "users#locations" I tried to extract the data this way: ---------------- in my locations action------------------ dasdasdd // used as a breakpoint to test whether this part was executed. it wasn't. current_user.update_attribute :Latitude, params[:lat] current_user.update_attribute :Longitude, params[:lng] With the debugging firefox console, I see a internal servers error 500. This might explain why the locations action was never executed. But why is there an error 500? Can anybody shine some light into how I might be wrong? ruby-on-rails ajax internal-server-error share|improve this question asked Aug 19 '13 at 2:06 Feverbeaver 7712 You can find plenty of information in the app/development.log as well as in the response body of the 500 error regarding the exception. We'd just be guessing what your problem is without knowing what the Exception being thrown is. –deefour Aug 19 '13 at 2:45 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote Since the dataType you have specified in your ajax call is json, try format.json { render 'users/locations' } instead of format.js in your controller share|improve this answer answered Aug 19 '13 at 3:12 Anchor 74081
Sign in Pricing Blog Support Search GitHub This repository Watch 451 https://github.com/spree/spree/issues/2517 Star 7,884 Fork 3,669 spree/spree Code Issues 137 Pull requests 77 Projects 0 Wiki Pulse Graphs New issue POST /orders/populate 500 Internal Server Error https://www.mobomo.com/2008/07/using-http-status-codes-for-rails-ajax-error-handling on ajax cart update #2517 Closed sibsfinx opened this Issue Feb 2, 2013 · 8 comments Labels None yet Milestone No internal server milestone Assignees No one assigned 3 participants sibsfinx commented Feb 2, 2013 Hello, I'm adding a product to cart with = form_for :order, :url => populate_orders_path, :remote => true, ... and handling events with .on('ajax:success') .on('ajax:error') and so on. I've added in orders_controller respond_to :html, :js internal server error and (in def populate) respond with(@order) do |format| format.html { redirect_to cart_path } format.js end but I'm getting the following error: (javascript console) POST http://localhost/orders/populate 500 (Internal Server Error) (server log) ActionView::MissingTemplate - Missing template spree/orders/populate, spree/store/populate, spree/base/populate, application/populate with {:locale=>[:ru], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee, :haml, :rabl], :versions=>[:v1]}. Spree Commerce member radar commented Feb 3, 2013 Please show us your Gemfile. … On 03/02/2013, at 4:39, Alexander Mescheryakov ***@***.***> wrote: Hello, I'm adding a product to cart with = form_for :order, :url => populate_orders_path, :remote => true, ... and handling events with .on('ajax:success') .on('ajax:error') and so on. I've added in orders_controller respond_to :html, :js and (in def populate) respond ***@***.***) do |format| format.html { redirect_to cart_path } format.js end but I'm getting the following error: (javascript console) POST http://localhost/orders/populate 500 (Internal Server Error) (server log) ActionView::MissingTemplate - Missing temp
applications is how to handle it when things go wrong. The user should be informed of the problem in a descriptive manner, but obviously the internal workings of the application should not be revealed. A generic and useful way to handle this problem is to use HTTP Status Codes to indicate the type of failure, and use the javascript to cope appropriately. In this example I will be using jQuery, but the principles behind are just as applicable to Prototype or any other Javascript library. Your Friends 403 and 500 Anyone who's built a Rails site is familiar with the 500 error. That's the generic exception code thrown whenever something goes wrong in your application. Users should, hopefully, never ever see this when they're using the site. However, oftentimes there are exceptions or errors that users should experience just as result of improperly filling out fields, permissioning, etc. So how do we differentiate? The Rails render method has the ability to render out an arbitrary HTTP Status Code (i.e. 500 for error, 404 for not found, and many more). The "403 Forbidden" code means that the server understood the request made of it, but is refusing to complete it. This sounds like an apt description for typically "caught" exceptions. So let's use the 403 code to intelligently handle the exceptions that we want to be seen by the user. In the controller Let's take the simplest example, an invalid record. If you are creating a record via AJAX, a flash[:error] with a render :action => "new" is not going to suffice. Let's try something like this instead: class ItemsController < ApplicationController def create Item.create!(params[:item]) # continue on your merry way if it works rescue ActiveRecord::RecordInvalid => e respond_to do |format| format.html { flash.now[:error] = "There was a problem creating the item." render :action => "new" } # Render out the validation failed message with a # 403 status code. format.js { render :text => e.message, :status => 403 } end end end All right, now that we've got it handled on the controller side, it's time to work some Javascript magic on our AJAX call. $('a#ajax_link').click(function() { $.ajax({ url: '/items', success:function(data, textStatus) { // do success things }, error:function(request, textStatus, errorThrown) { // Use the specific message for a 403, but // a generic failure message for a 500 var message = (request.status == 403) ? request.responseText : "An unknown error occurred. Support has been contacted."; // Simple alert for example, but you can handle // however you want, such as populating an error message // div and making it appear. alert(message); } return false; }); }); Now when you