首页 \ 问答 \ 如何检查图像是否存在于Rails中?(How to check if image exists in Rails?)

如何检查图像是否存在于Rails中?(How to check if image exists in Rails?)

<%= image_tag("/images/users/user_" + @user_id.to_s + ".png") %>

你如何检查是否有这样的图像,如果没有,则不显示任何内容?

在Rails 3.07中工作。


<%= image_tag("/images/users/user_" + @user_id.to_s + ".png") %>

How do you check to see if there is such an image, and if not, then display nothing?

Working in Rails 3.07.


原文:https://stackoverflow.com/questions/7969241
更新时间:2022-05-08 17:05

最满意答案

如何使用具有更好移除时间的数据结构(如HashSet或TreeSet)? 所以使用数组列表的主要原因是由于O(1)访问记录的快速访问时间。 但是如果你想设置差异,那么也许你应该使用集合。 只是一个想法。


What about using a data structure that has a much better removal time, such as HashSet or TreeSet? So the big reason to use an arraylist is due to the fast access time O(1) to access records. But if you are trying to set difference then maybe you should use sets. Just a thought.

相关问答

更多
  • 如何使用具有更好移除时间的数据结构(如HashSet或TreeSet)? 所以使用数组列表的主要原因是由于O(1)访问记录的快速访问时间。 但是如果你想设置差异,那么也许你应该使用集合。 只是一个想法。 What about using a data structure that has a much better removal time, such as HashSet or TreeSet? So the big reason to use an arraylist is due to the fas ...
  • clear()的源代码: public void clear() { modCount++; // Let gc do its work for (int i = 0; i < size; i++) elementData[i] = null; size = 0; } removeAll()的源代码removeAll()在AbstractCollection定义): public boolean removeAll(Collection c) { ...
  • 正如Milkmaid所说,这不是你应该如何进行基准测试,但我相信你得到的结果仍然有效。 让我们看看“幕后”,看看两个实现: ArrayList.removeAll调用batchRemove : private boolean batchRemove(Collection c, boolean complement) { final Object[] elementData = this.elementData; int r = 0, w = 0; boolean modifie ...
  • 我不知道只能删除所选项目的方法。 但创建扩展方法是直接的: public static class ExtensionMethods { public static int Remove( this ObservableCollection coll, Func condition) { var itemsToRemove = coll.Where(condition).ToList(); foreach (va ...
  • 该方法本身不会复制数组,并且不太可能是原因(虽然对我来说不安全,因为它不能保护您不会发生其他意外错误)。 我会说你可能会从数组元素中传递的结构中复制字符串,最终你会遇到DLL和EXE模块的字符串分配器,导致访问冲突。 确保您的调用者不复制该字符串,如果您需要复制,请执行以下操作: GetFlagsOfRun(..., flags) { FlagData& a = ... CString b = (LPCTSTR) a.Name; // Not a.Name directly! ... } Th ...
  • subList的Javadoc声明: 如果支持列表(即此列表)在结构上以除返回列表之外的任何方式进行修改,则此方法返回的列表的语义将变为未定义。 (结构修改是那些改变了这个列表的大小,或以其他方式扰乱它的方式,正在进行的迭代可能会产生不正确的结果。) 这意味着调用removeAll可能会使subList返回的列表无效。 此外, addAll的Javadoc声明: 如果在操作正在进行时修改了指定的集合,则此操作的行为是不确定的。 ( 请注意,如果指定的集合是此列表,则会发生这种情况,并且它是非空的 。) 在您 ...
  • 性能差异的原因是内存访问模式:访问内存中连续的元素比访问内存更快(由于内存预取,CPU高速缓存等) 当您最初填充集合时,您会在内存中顺序创建所有元素,因此当您遍历它时(foreach,removeAll等),您正在访问缓存友好的连续内存区域。 当你洗牌集合时 - 元素在内存中保持相同的顺序,但指向这些元素的指针不再是相同的顺序,所以当你遍历集合时,你将访问例如第10个,第1个,那么第五个元素非常缓存不友好并且破坏了表现。 您可以更详细地查看此效果可见的位置: 为什么筛选未排序的列表比筛选已排序的列表要快 T ...
  • 你没有使用input while (scan.hasNextLine()) { Scanner input = new Scanner(scan.nextLine()); input.useDelimiter(","); while (scan.hasNext()) { String md5 = scan.next(); temp.add(md5); } } 我想你打算这样做: while (scan.hasNextLine()) { Scanner input = n ...
  • 甚至更快是mycollection.source = []; (而不是mycollection.source = new Array() ) 另一种选择是使用链接列表和对象池。 对象池允许对象重写其属性,而不是删除对象并创建新对象。 如果你把它们放在一个链表中而不是一个数组中,循环它们会快得多。 所以,如果你只是想循环一堆对象,去链接列表,但如果你需要做任何排序,那么数组和向量会更快。 另一个问题是内存使用。 不仅仅是为了让应用程序运行内存更小,而且您声明的对象越多,垃圾收集器在清理时就必须执行的工作越多。 ...
  • 或者,您也可以检查频率。 Collections.frequency(arrayList, number) public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add(5); arrayList.add(1); arrayList.add(5); arrayList.add(1); arrayLis ...

相关文章

更多

最新问答

更多
  • 您如何使用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)