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

tangmonk · 2015年01月29日 · 最后由 ken 回复于 2015年01月29日 · 1926 次阅读

比如说 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:

需要 登录 后方可回复, 如果你还没有账号请 注册新账号