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
最满意答案
纯色渲染比渐变更快,因此可以解释更改主题时的改进。 您是否缓存生成的图形图像,因此它们只需渲染一次? 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 ...
-
RecyclerView滚动滞后(RecyclerView scroll lags)[2022-03-11]
尝试一次,在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 运行一个应用程序来测试性能(不要担心乱糟糟的布局) 如果效果明显,则设置自动调整遮罩(并在需要时在代码中进行布局 ...
-
当im渲染印地语字体时,UICollectionView滞后滚动(UICollectionView lags on scroll when im rendering Hindi font)[2021-12-13]
我会推荐阅读这篇文章。 它为UITableViews和UICollectionViews提供了一套全面的滚动优化实践 UPD 在你的情况下,我会看看TextKit 文档 : 从UITextView类创建的文本视图旨在显示大量文本。 底层的UITextView是一个强大的布局引擎,称为Text Kit。 如果您需要自定义布局过程,或者需要介入该行为,则可以使用Text Kit。 希望这可以帮助。 Finally, I found the issue causing scroll lag: The lag ca ... -
Core Plot滚动中断(Core Plot scrolling interruption)[2022-01-11]
我们对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).