Rails 3, :json => @model.to_json OR :json => @model
Asked Answered
R

1

0

I just wandered the difference between:

format.json { render :json => @post, :include => [ :user ] }

...and

format.json { render :json => @post.to_json(:include => [ :user ]) }

They both seem to work?

Rooftree answered 4/3, 2012 at 17:45 Comment(0)
S
2

it's the same. if you have a look at actionpack renderers.rb you will see how it works:

add :json do |json, options|
  json = json.to_json(options) unless json.kind_of?(String)
  json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
  self.content_type ||= Mime::JSON
  json
end
Sulcate answered 4/3, 2012 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.