Rails3 CSV放置""(Rails3 CSV putting "" instead of actual quotes)
与此问题类似,除了我不在整个项目的任何地方使用
html_safe
。我在
index.csv.erb
生成一个CSV文件,如下所示:<%= response.content_type = 'application/octet-stream' CSV.generate do |csv| @persons.each do |person| csv << [ person[:name], person[:nickname] ] end end %>
问题:如果数据库中的昵称为NULL(ActiveRecord / MySQL),那么CSV文件关联元素将变为
""
。 我期望""
,甚至什么也不是。结果文件示例:
Nicolas, Nico Joe, ""
我怎样才能防止这种情况发生?
Similar to this question except I don't use
html_safe
anywhere in the whole project.I generate a CSV file in
index.csv.erb
like this:<%= response.content_type = 'application/octet-stream' CSV.generate do |csv| @persons.each do |person| csv << [ person[:name], person[:nickname] ] end end %>
PROBLEM: If nickname is NULL in the database (ActiveRecord/MySQL) then the CSV file associated element becomes
""
. I would expect""
, or even nothing at all.Result file sample:
Nicolas, Nico Joe, ""
How can I prevent this from happening?
原文:https://stackoverflow.com/questions/7358509
最满意答案
您在引用的代码中需要一个
else
。 当dateIsGreaterThanDate
测试为false时,您希望它是什么颜色?You need an
else
in the code you quoted. What colour do you want it to be when thedateIsGreaterThanDate
test is false?
相关问答
更多-
滚动时TableView重新排列/创建空白单元格。(TableView rearranging / creating blank cells when scrolling. Swift)[2022-07-14]
你应该这样做: public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return Int(numberofContacts) } public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { ... -
最简单的方法是: [myTable reloadRowsAtIndexPaths:myTable.indexPathsForVisibleRows withRowAnimation:UITableViewRowAnimationAutomatic]; 但是,由于您正在寻找更优化的方法,以下情况会更好: 单击按钮,在目标方法中,迭代可见单元格,并在每个单元格中进行相关更改。 - (IBAction)btnDone:(id)sender { for (UITableViewCell* cell in ...
-
由于Cell的可重用性,它正在讨价还价。 而不是在didSelect中设置Checkmark ,而是尝试在cellForRowAtIndexPath设置。 您还需要创建这样的model类来解决您的问题 class ModelClass: NSObject { var isSelected: Bool = false //Declare other property that you are using cellForRowAtIndexPath } 现在检查这个isSelected in ...
-
你让自己成了无限循环。 每次显示一个单元格时,都会调用reloadData 。 在每次reloadData之后,重新加载tableView并再次显示所有单元格。 这将再次调用reloadData。 之后,再次显示第一个单元格。 等等。 尝试将对reloadData的调用放入if中,以增加tableView中的项目数。 喜欢这个: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowA ...
-
当您重复使用单元格时,旧值仍然存在,因此每次使用dequeueReusableCellWithIdentifier时,您都需要重置为默认值或仍在其中缓存的最后值。 在您的特定情况下,您需要删除从单元格创建的按钮或将其设置为隐藏在else语句中。 从苹果文档: tableView的表视图的数据源实现:cellForRowAtIndexPath:在重用单元格时应始终重置所有内容。 实现此目的的最佳方法是根据需要创建一个包含所有组件的自定义单元格(按钮,标签等),同时将新的自定义单元格出列,并根据需要将属性隐藏为 ...
-
当我滚动我的tableview时,我的单元格的一些文本会改变颜色(some text of my cells changes color when I scroll my tableview)[2023-05-04]
您在引用的代码中需要一个else 。 当dateIsGreaterThanDate测试为false时,您希望它是什么颜色? You need an else in the code you quoted. What colour do you want it to be when the dateIsGreaterThanDate test is false? -
如果您希望不重复使用您的单元格,请尝试将其作为具有唯一标识符的UITableViewCell的子类,并且不要将该标识符与其他单元格一起使用。 我还没有测试过,只希望它能解决你的问题。 PS。 如果文本字段的文本仍然被覆盖,请检查单元格的类文件(比如使用if-else语句检查文本字段的文本是否为空)。 详细的工作流程:在cellForRowAtIndexPath()中 ,在单元格出列后,通常会设置自定义单元格的某些属性以刷新它所拥有的数据。 要实现这一点,您需要在单元格的类文件的属性上添加didSet观察者。 ...
-
该代码的问题在于,您永远不会撤消添加项目时所做的更改。 即使单元格变空并且您从不检查特定值,也永远不会删除graphic 。 此外,如果添加null项, items.toString()可能会导致NPE。 也无需重新创建Text元素。 此外,您永远不会将项目与特定值进行比较。 final String specificValue = ... new TableCell
() { private final Text newText; ... -
由于我没有在此收到回复,因此我向Titanium Appcelerator Q&A网站发布了相同的问题。 看来我以前学习Titanium的教程已经过时了。 此后不推荐使用auto标记,现在建议使用Titanium API中包含的常量。 非常感谢我在其他主题上的答案。 解决我的问题的答案: auto已弃用单位。 而是使用FILL或SIZE 。 http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TableViewRow-propert ...
-
如果我为tableview单元格设置动画,则表格视图滚动不会停止(Tableview scroll is not stopping on tap if i animate tableview cells)[2022-01-06]
注意: 这是使用animateWithDuration ...方法之一的动画的正常行为。 如果你想在动画期间进行用户交互,你可以尝试像我已经展示的那样。 你只需要尝试这样: func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { let rotationTransform = CATransform3DScale( ...