是否可以通过业务逻辑限制对资产的访问?

时间:2012-07-20 19:36:22

标签: ruby-on-rails-3 permissions assets

我创建了账单,应该可以从管理员打开,但不能作为普通用户打开。此法案pdf将在app / assets / pdfs中的某个业务流程之后创建。

 assets_pdf_url if user_signed_in?

是否可以通过某种规则限制特定资产?

1 个答案:

答案 0 :(得分:1)

将受限制的资源存储在公用文件夹之外的某个文件夹中,因此只能通过访问URL来访问它们,然后创建使用send_file或send_data的操作。这样你就可以把它包装成你想要的任何逻辑。

# in controller
def show
  @bill = Bill.find(params[:id])
  if user_signed_in?
    send_file Rails.root.join('bill_pdfs',"#{@bill.id}.pdf")
  else
    redirect_to '/', :error => "Only logged in users may download"
  end
end