Skip to content

Commit

Permalink
Merge pull request #2321 from omjokine/master
Browse files Browse the repository at this point in the history
JSONP should use mimetype application/javascript
  • Loading branch information
josevalim committed Apr 29, 2012
2 parents e6ab0d5 + b4e1903 commit d4dd1af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/metal/renderers.rb
Expand Up @@ -91,7 +91,10 @@ module All


add :json do |json, options| add :json do |json, options|
json = json.to_json(options) unless json.kind_of?(String) json = json.to_json(options) unless json.kind_of?(String)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank? unless options[:callback].blank?
json = "#{options[:callback]}(#{json})"
self.content_type ||= Mime::JS
end
self.content_type ||= Mime::JSON self.content_type ||= Mime::JSON
json json
end end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/render_json_test.rb
Expand Up @@ -102,7 +102,7 @@ def test_render_json_with_status
def test_render_json_with_callback def test_render_json_with_callback
get :render_json_hello_world_with_callback get :render_json_hello_world_with_callback
assert_equal 'alert({"hello":"world"})', @response.body assert_equal 'alert({"hello":"world"})', @response.body
assert_equal 'application/json', @response.content_type assert_equal 'application/javascript', @response.content_type
end end


def test_render_json_with_custom_content_type def test_render_json_with_custom_content_type
Expand Down

3 comments on commit d4dd1af

@carlosantoniodasilva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is a valid entry for changelog?

@rafaelfranca
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@carlosantoniodasilva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR: #6047

Please sign in to comment.