我正在开发一个允许会员进行调查的应用程序(会员与Response有一对多的关系).Response保存member_id,question_id及其答案.
调查全部或全部提交,因此如果该成员的响应表中有任何记录,则他们已完成调查.
我的问题是,如何重新编写下面的查询,以便它实际工作?在SQL中,这将是EXISTS关键字的主要候选者.
def surveys_completed
members.where(responses: !nil ).count
end
Run Code Online (Sandbox Code Playgroud) 在之前的版本中我可以做到:
$('#search').typeahead({
name: 'Search',
remote: '/search?query=%QUERY'
});
Run Code Online (Sandbox Code Playgroud)
但是自0.10更新以来,typeahead.js要求我们定义source哪些无法工作.如何在不定义数据集功能的情况下定义远程?
javascript autocomplete remote-server typeahead typeahead.js
这是您使用jQuery Tokeninput和ActsAsTaggableOn自动完成的方式.
在我的情况下,我使用嵌套的形式,但它不重要.以下所有内容都是有效的代码.
产品型号:
attr_accessible :tag_list # i am using the regular :tag_list
acts_as_taggable_on :tags # Tagging products
Run Code Online (Sandbox Code Playgroud)
产品控制器:
#1. Define the tags path
#2. Searches ActsAsTaggable::Tag Model look for :name in the created table.
#3. it finds the tags.json path and whats on my form.
#4. it is detecting the attribute which is :name for your tags.
def tags
@tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:q]}%")
respond_to do |format|
format.json { render :json …Run Code Online (Sandbox Code Playgroud) ruby autocomplete ruby-on-rails acts-as-taggable-on ruby-on-rails-3
如何让sublime text 2响应txmtubuntu中的url方案?这可以通过subl-handler在OSX中实现,在Windows中通过SublimeProtocol实现.
我有这张桌子messages;
sender_id recipient_id
1 2
1 3
1 3
2 1
3 1
2 3
Run Code Online (Sandbox Code Playgroud)
我希望选择以下行:
sender_id或.receiver_idcurrent_user.id即我想从表中选择唯一的sender_id = 2或者recipient_id = 2我需要这个结果:
sender_id recipient_id
2 1
2 3
Run Code Online (Sandbox Code Playgroud)
怎么做?
为什么?因为我希望建立一个类似于Facebook的收件箱,其中汇总了已发送和已接收的邮件,此查询是目前为止的瓶颈.
我使用的是rails 3.2和Postgres 9.3.
关于以下代码:
if a == 1
return "a is one"
end
Run Code Online (Sandbox Code Playgroud)
当我在IRB中执行它时,它给了我
LocalJumpError:意外
return
但是当我在Rails应用程序中添加相同的代码时,它运行完美.
我是否真的必须避免从块内部返回显式值?为什么Rails应用程序没有问题呢?
autocomplete ×2
ruby ×2
aggregate ×1
duplicates ×1
irb ×1
javascript ×1
postgresql ×1
sql ×1
sublimetext2 ×1
typeahead ×1
typeahead.js ×1