Rails Rails 4.2 Scaffold 生成的 Controller 中的 new , 为什么会有 respond_with 啊?

tangmonk · January 29, 2015 · Last by ken replied at January 29, 2015 · 1927 hits

比如说 scaffold 一个 user

rails g scaffold User

UsersController:

def new
  @user = User.new
  respond_with(@user)
end

如果 在浏览器中请求 JSON 格式的 http://localhost:3000/users/new.json

返回

{"id":null,"name":null,"nick_name":null,"created_at":null,"updated_at":null}

有这个必要吗?

http://guides.rubyonrails.org/4_2_release_notes.html

respond_with and the corresponding class-level respond_to have been moved to the responders gem. Add gem 'responders', '~> 2.0' to your Gemfile to use it:

You need to Sign in before reply, if you don't have an account, please Sign up first.