首页 \ 问答 \ 如何在字符串属性中搜索id(SQL)(How do I search an id in a string attribute (SQL))

如何在字符串属性中搜索id(SQL)(How do I search an id in a string attribute (SQL))

在我的聊天应用程序中,我想计算学生模型的响应率。

我使用slug属性跟踪所有会话。 这是一个像这样的字符串: 270-77 ,这意味着这是学生270和招聘人员77之间的对话。

现在我想查看一个学生的谈话次数。 这是我的代码:

def calculate_number_of_conversations(@student)
  @conversations = Conversation.where("slug LIKE ?", "%#{params[@student]}")
end

重要的是它应该只搜索字符串的第一部分,因为slug的第一个数字始终是学生的id。


In my chat app I want to calculate the response rate for student model.

I track all conversations with a slug attribute. It's a string like this: 270-77, which means that this is a conversation between student 270 and recruiter 77.

Now I want to check how many conversations one student has. Here is my code:

def calculate_number_of_conversations(@student)
  @conversations = Conversation.where("slug LIKE ?", "%#{params[@student]}")
end

Important is that it should only search in the first part of the string because the first number in slug is always a student's id.


原文:https://stackoverflow.com/questions/46001727
更新时间:2021-08-27 15:08

最满意答案

您将原始内容放在新div中。

使它看起来像你的图像将是id =“优惠券”div。 就这样我们清楚它是这样开始的:

<div id="coupons">
<div class="coupon" style="background:url(images/bg1.png);">

您需要将该div(及其所有内容)移动到id =“popup”div的结束标记之后。


You placed the original content inside of your new div's.

To make it look like your image that would be the id="coupons" div. Just so we're clear it's the one that starts like this:

<div id="coupons">
<div class="coupon" style="background:url(images/bg1.png);">

You need to move that div (and all it's contents) to just after the end tag of the id="popup" div.

相关问答

更多
  • 有许多方法可以水平居中。 但每种方式都适用于不同的条件。 在这里,我添加了三个版本的中心小提琴: http : //jsfiddle.net/kizu/5WMNE/ 只是文本的中心:便宜,但不公平。 对于现代浏览器,您可以使用transform: translate(-50%,0)来对齐块,因为变换中的百分比是从元素的维度计算的,而不是从父级的维度计算的。 但它在IE中不起作用,但是可以编写可以模拟它的表达式。 如果你添加了额外的包装器,你可以使用inline-block来真正居中。 There are a ...
  • Noope,你必须给父母一些宽度和一些高度。 在我读这篇文章之前,我并不完全理解CSS Floats: http://alistapart.com/article/css-floats-101 Noope, you'll have to give the parent some width and some height. I didn't fully understand CSS Floats until I read this article: http://alistapart.com/article ...
  • 它是不可见的,因为你已经left:-100px on .colA 删除那种风格,它就像你想象的那样(我认为)。 更新:抱歉: 设置为left:0px on .colA 。 此外,您不需要left:-100px ie7的表格为left:-100px 。 It's not visible because you have left:-100px on .colA Remove that style, and it works as (I think) you expect. update: sorry: Set ...
  • 使用float:right这个类: .text-block { float: right;/*Add this*/ width: 230px; height: 50px; display: inline-block; background: #acbafe; } 小提琴 Use float:right to this class: .text-block { float: right;/*Add this*/ width: 230px; he ...
  • 它有可能但仅在某些条件下。 元素必须在一个容器元素内,其尺寸(有效宽度和高度)应该与元素容器相同(一个简单的javascript可以做到这一点)并且它应该有{position:relative}。使这个容器位置本身就像它的孩子本来会的。就是这样。 it is possible but under certain conditions only. The element has to be inside a container element whose dimensions(effective width ...
  • 您可以尝试以下方法 width: auto; height: auto; top: 50%; left: 50%; // don't declare right or bottom transform: translateX(-50%) translateY(-50%); 它会将元素的左边缘放在中心(左边:50%;),然后将其向左轻推(translateX(-50%))。 类似地,对于垂直中心(顶部:50%;)和(translateY(-50%))。 You could try the following ...
  • 您将原始内容放在新div中。 使它看起来像你的图像将是id =“优惠券”div。 就这样我们清楚它是这样开始的:
    您需要将该div(及其所有内容)移动到id =“popup”div的结束标记之后。 You placed the original content inside of your new div's. To make it look li ...
  • 这样的事情应该这样做: function getStyle(el, prop) { var doc = el.ownerDocument, view = doc.defaultView; if (view && view.getComputedStyle) { return view.getComputedStyle(el, '')[prop]; } return el.currentStyle[prop]; } var all = document.getElementsByTag ...
  • 事实证明它毕竟是绝对定位,但结合计算的页面高度。 应用程序的根组件具有计算的CSS高度,如calc(100vh - 200px)。 用高度替换该高度:在组件的@print介质中自动删除位置:绝对从弹出窗口到实际工作。 作为旁注,我打赌如果根组件有任何固定高度,这个问题就会出现,而不一定只是计算出的高度。 简介:如果您遇到此问题,请留意固定高度父元素与绝对定位结合使用。 Turns out it was absolute positioning after all, but in combination wi ...
  • 那么,为什么每个新的绝对定位元素都会在之前绝对定位的元素top-left-pos上呈现另一个位置? 为什么another-pos元素不会呈现为下一个块元素? “绝对定位的元素相对于最近定位的祖先(非静态)定位。如果定位的祖先不存在,则使用初始容器。” Src: CSS /职位 这意味着如果你有1或10个元素使用position: absolute ,它们都从相同的top / left位置开始(如果在css规则中省略这些值)。 因此,它们也被取出正常流量,在下面的样本显示中,使用正常流量的另一个div #an ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。