Rails Goodness : What is Jsonify in Rails, Why is needed for REST based controllers

JSONIFY is one of the original ways on how you can Rails converts its Models to JSON Views.

With .jsonfiy in your View, you can move the shenanigans of converting the models to JSON views .jsonify file.

It will also allow you to filter out  or convert the model to the desired JSON output.

If you are using pure REST controllers with no views, you need to have a .jsonfiy file (blank file in view folder is fine as well), for the controllers and rspec to work.

sample .jsonfiy file

json.applications(@applications) do |app|
  json.id         app.id
  json.name       app.name.force_encoding(Encoding::UTF_8)
  json.guid       app.guid.to_s
  json.icon       app.icon_path

  json.created_at        app.created_at.localtime
  json.created_at_human  l(app.created_at.localtime, :format => :human_date)
  json.updated_at        app.updated_at.localtime
  json.updated_at_human  l(app.updated_at.localtime, :format => :human_date)
end

Comments

Popular posts from this blog

Apache Airflow Wait Between Tasks

Hibernate Interview Questions

Java Spring Interview Questions