Skip to content

Instantly share code, notes, and snippets.

@brandoncordell
Created December 14, 2017 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandoncordell/ac4e7e59e2ad85cb25309cecb7b0b1f2 to your computer and use it in GitHub Desktop.
Save brandoncordell/ac4e7e59e2ad85cb25309cecb7b0b1f2 to your computer and use it in GitHub Desktop.
respond_to js and json
module Admin
class EcardProgramsController < BaseController
def index
@ecard_programs = EcardProgram.all
end
def create
@ecard_program = EcardProgram.new(ecard_program_params)
respond_to do |format|
if !@ecard_program.save
format.html { redirect_to admin_ecard_programs_path }
format.js
else
format.js { render json: { success: false }, status: :unprocessable_entity}
end
end
end
private
def ecard_program_params
params.require(:ecard_program).permit(:name, :code)
end
end
end
== Getting this error in my browser ==
Uncaught SyntaxError: Unexpected token :
at processResponse (rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:246)
at rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:173
at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:230)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment