Reputation: 2681
This is the code generated by scaffolding
def index
@swimming_classschedules = Swimming::Classschedule.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @swimming_classschedules }
end
end
Why it is generated with two formats . It seems I only use html format. When does json format get used?
Upvotes: 1
Views: 257
Reputation: 2653
Sometimes we need the data in the format of json. Ruby on Rails is one of the must used framework as backend of mobile application (android, ios). The android and ios support data in the format of json. so the data of json format is generated when scaffloding. In case of web application it is not necessary to generate data in the format of json.
Upvotes: 2
Reputation: 6567
I actually find them quite useful when I start doing REST-ful API or AJAX-y web service calls, so I tend to leave them there (unless I'm certain that that particular action would or should never return JSON).
Upvotes: 1