新手问题 Active Record 的问题

ThanksSirAlec · January 19, 2018 · Last by ThanksSirAlec replied at January 19, 2018 · 1138 hits

我想在要写一个接口,返回用户的名字和邮箱 我的index.json.jbuilder是这样的

json.users @user do |user|
  json.name user.name
  json.email user.email
end

但是有时候按搜索条件,这个@user只有一个,这个时候就会报 undefined method map 的错误,请问这个问题怎么解决

1 Floor has deleted

你的搜索咋个写的 贴出来。

controller 里的查询不论搜索条件如何都应该用相同的查找方法(例如 where),保证查询结果是 ActiveRecord_Relation 或数组

Reply to coderliu

多谢指教,明白了

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