In application.js …
$(document).ready(function () {
$("#new_academic_formation").validate({
debug: true,
rules: {
"academic_formation[id]": {
required: true,
minlength: 3,
remote: "/academic_formations/check_id"
}
}
});
});
In my academic_formations_controller.rb
def check_id
@academic_formation = AcademicFormation.find(params[:id])
respond_to do |format|
format.json { render :json => !@academic_formation }
end
end
And finally in file routes.rb
resources :academic_formations
match "/academic_formations/check_id" => 'academic_formations#check_id'
The problem is that instead of calling the action check_id rails is calling the action show.
You’ll need to move
match "/academic_formations/check_id" => 'academic_formations#check_id'beforeresources :academic_formations.This is straight from the docs.
“Rails routes are matched in the order they are specified, so if you have a
resources :photosabove aget 'photos/poll'the show action’s route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.”OR
Since yours is a resourceful route, you may add a route as, if it applies to a collection(you can read more about that in the docs linked above) and if it’s a
getmethod as :