首页 \ 问答 \ CanCanCan可以授权相关对象(CanCanCan authorize associated objects)

CanCanCan可以授权相关对象(CanCanCan authorize associated objects)

我的Routes.rb:

resources :users
resources :clients do
  resources :branches
end

我在Ability.rb中有这个。 用户只能更新自己的客户。

  can [:update], Client, :id => user.clients.pluck(:id)

用户还应该能够:create,:update,:显示属于客户端的分支。 它可能看起来像这样:

  can [:create, :update, :show], Branch, :client => { :id => user.clients.pluck(:id) }

它适用于:update,:show,但不适用于:create。 这是因为new Branch在创建之前没有client_id。 我如何使其工作:创建?


My Routes.rb:

resources :users
resources :clients do
  resources :branches
end

I have this in Ability.rb. User can update only his own clients.

  can [:update], Client, :id => user.clients.pluck(:id)

User should be also able to :create, :update, :show branches which belong to client. It might look somehting like this:

  can [:create, :update, :show], Branch, :client => { :id => user.clients.pluck(:id) }

It works for :update, :show, but not for :create. It's because new Branch doesn't have client_id before create. How do I make it work for :create?


原文:https://stackoverflow.com/questions/28624916
更新时间:2023-10-14 17:10

最满意答案

纯色渲染比渐变更快,因此可以解释更改主题时的改进。 您是否缓存生成的图形图像,因此它们只需渲染一次? iOS版本的Plot Gallery示例应用程序使用表格视图来显示图形缩略图,但它可能会为您提供一些有关如何构建应用程序以获得更好性能的建议。


Solid colors render a lot faster than gradients, so that explains the improvement when you changed themes. Are you caching the generated graph images so they only have to render once? The iOS version of the Plot Gallery example app use a table view to show the graph thumbnails, but it might give you some ideas how to structure your app for better performance.

相关问答

更多
  • 您可能还会遇到的两个原因 1.谷歌分析 如果设置为计算每个单元格视图。 它开始很快但随后变慢并且滞后,因为当您滚动太快时,谷歌分析会写入i / o(可能是一些缓存)。 2. DateTime解析 如果为每个单元格设置,则DateFormatter很难。 如果可能,请确保您有一个单身人士。 2 reasons that you might also encounter 1. Google analytics If you set up to count every cell view. It starts f ...
  • 好的,所以对此没有一个简单的答案,但迈克帮我解决的解决方案涉及从故事板原型单元转移,而是通过单元类以编程方式创建单元格。 迈克大声喊出来给我这个解决方案! 这是新代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MessagingTableViewCell *cell = [tableView dequeueReusableCellW ...
  • 纯色渲染比渐变更快,因此可以解释更改主题时的改进。 您是否缓存生成的图形图像,因此它们只需渲染一次? iOS版本的Plot Gallery示例应用程序使用表格视图来显示图形缩略图,但它可能会为您提供一些有关如何构建应用程序以获得更好性能的建议。 Solid colors render a lot faster than gradients, so that explains the improvement when you changed themes. Are you caching the genera ...
  • 尝试一次,在AndroidManifest.xml中 android:hardwareAccelerated="true" I realized that it's lagging because it's loading the .ttf file every time it binds when scrolling through the list. Loading it just once solved the problem.
  • 解决了使用css中的以下内容: 而不是在css #menu选择器中使用以下内容 overflow: hidden; 改用它 overflow-y: scroll; overflow-x: hidden; -webkit-overflow-scrolling: touch; Solved using the following in the css: rather than using the following in the css #menu selector overflow: hidden; u ...
  • 你想要做的是节流滚动事件。 消除事件意味着事件在一定时间之后才能再次发射。 限制事件意味着事件每个时间段只能激发很多事件。 这是节流事件的功能(信用: http : //sampsonblog.com/749/simple-throttle-function ) // Create the listener function function throttle (callback, limit) { var wait = false; // Initially, we ...
  • 编辑:无需尝试自动调整掩码,只需阅读这篇关于UICollectionView性能提升的简短文章http://noxytrux.github.io/blog/2014/09/25/ios8-weirdness-part3-laggy-uicollectionview/ 这可能是一个自动布局开销 。 考虑尝试自动调整掩码。 您可以提交所有内容并进行实验: 关闭单元格xib文件上的autolayout 运行一个应用程序来测试性能(不要担心乱糟糟的布局) 如果效果明显,则设置自动调整遮罩(并在需要时在代码中进行布局 ...
  • 我会推荐阅读这篇文章。 它为UITableViews和UICollectionViews提供了一套全面的滚动优化实践 UPD 在你的情况下,我会看看TextKit 文档 : 从UITextView类创建的文本视图旨在显示大量文本。 底层的UITextView是一个强大的布局引擎,称为Text Kit。 如果您需要自定义布局过程,或者需要介入该行为,则可以使用Text Kit。 希望这可以帮助。 Finally, I found the issue causing scroll lag: The lag ca ...
  • 我们对Core Plot代码的release-2.0分支上的事件处理和相关委托方法进行了一些更改。 从GitHub获取最新代码并切换到release-2.0分支以获取更新的代码。 请注意,此更新需要Accelerate框架,并提高master分支上1.x版本的最低系统要求。 I fix this problem in my code, using graph plot space delegate instead of CPTPlot delegate. -(BOOL)plotSpace:(CPTPlotS ...
  • 将绘图空间的globalXRange设置为location = 0的range , range =最后一个柱的位置(加上条的宽度的偏移量)。 Set the globalXRange of the plot space to a range with location = zero and range = the location of the last bar (plus an offset for the width of the bar).

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)