Skip to content

Instantly share code, notes, and snippets.

View antonioforn's full-sized avatar

Antonio Fornerón antonioforn

View GitHub Profile
@antonioforn
antonioforn / gist:8030b4d7e09124b91dec23a932113458
Created February 2, 2017 19:22
rails respond_to with json format example
first your route
ROUTES.RB
get 'student' => 'students#search', defaults: { format: 'json' }
SEARCH METHOD IN CONTROLLER
def search
@student = Student.search_student params (this customized method in Student model returns a relation)
#byebug
<html>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="runnable.css" rel="stylesheet" />
<!-- Load jQuery and the validate plugin -->
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<html>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="runnable.css" rel="stylesheet" />
<!-- Load jQuery and the validate plugin -->
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>