Gem devise 如何结合 grape 写注册部分的 api?

stephen · 2014年07月02日 · 最后由 ruby_sky 回复于 2014年07月02日 · 2169 次阅读

devise 如何结合 grape 写注册部分的 api?

def create
  build_resource(sign_up_params)

  if resource.save
    yield resource if block_given?
    if resource.active_for_authentication?
      set_flash_message :notice, :signed_up if is_flashing_format?
      sign_up(resource_name, resource)
      respond_with resource, location: after_sign_up_path_for(resource)
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
      expire_data_after_sign_in!
      respond_with resource, location: after_inactive_sign_up_path_for(resource)
    end
  else
    clean_up_passwords resource
    respond_with resource
  end
end

研究 devise 的注册的这段代码。

@ruby_sky 应该不用这么复杂,而且在 grape 中是怎样调用 build_resource 之类? 直接一个 User.new(params)OK 吗?加密 devise 是哪个?我在搜索 devise 代码时,找不到 build_resource

#2 楼 @stephen 你研究主干线嘛,然后简化。

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