Created
December 14, 2017 16:12
-
-
Save brandoncordell/ac4e7e59e2ad85cb25309cecb7b0b1f2 to your computer and use it in GitHub Desktop.
respond_to js and json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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