Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 保护RABL gem(Ruby on Rails)_Ruby On Rails_Security_Api_Rabl - Fatal编程技术网

Ruby on rails 保护RABL gem(Ruby on Rails)

Ruby on rails 保护RABL gem(Ruby on Rails),ruby-on-rails,security,api,rabl,Ruby On Rails,Security,Api,Rabl,我用的是rabl gem show.rabl object @user attributes :id, :name, :realname, :email 我得到 {"user":{"id":1,"name":"username","email":"mail@mail.com"}} 问题是,任何人都可以看到这个信息,如果他们打开链接 在my db中,记录后的每个用户都有唯一的auth_令牌字段 问题是-我只想通过此链接查看此信息-创建支票或使用一些授权gem,如cancan 原始示例,以便您能

我用的是rabl gem

show.rabl

object @user
attributes :id, :name, :realname, :email
我得到

{"user":{"id":1,"name":"username","email":"mail@mail.com"}}
问题是,任何人都可以看到这个信息,如果他们打开链接

在my db中,记录后的每个用户都有唯一的auth_令牌字段


问题是-我只想通过此链接查看此信息-

创建支票或使用一些授权gem,如
cancan

原始示例,以便您能够掌握(未经测试,在电话上写下…):

class MyController
创建支票或使用一些授权gem,如
cancan

原始示例,以便您能够掌握(未经测试,在电话上写下…):

class MyController
class MyController < ApplicationController
  before_filter :check_token_if_json
  respond_to :html, :json

  def show
    @user = User.find params[:id]

    respond_with(@user)
  end

  private

  def check_token_if_json
    if params[:format] == 'json'
      raise "Access denied" and return unless params[:token] == 'my_required_token'
    end
end