我有一系列数据,例如我希望在几个地方存储和引用的时间(早上7点,上午7点30分等).
1)我应该在哪里存储这些数据?我最初在我的数据库中思考(我正在使用mongoid),但我不确定这是否过度杀戮.
2)我将如何引用它?让我们说,从下拉菜单中.
我是铁杆的新手,很抱歉,如果这个太容易了.
我的模型中有一个datetime属性,我尝试用3个表单元素将值放在其中.第一个是日期,是一个输入形式(我使用bootstrap-datepicker-rails,我想坚持下去).在第二个我想要一个小时的选择框,第三个是分钟.
所以我看到我可以使用DateHelpers datetime_select但是我不能再使用bootstrap-datepicker了.那么通过使用多个表单输入元素来填充属性(日期时间)的正确方法是什么.我看到有类似assign_multiparameter_attributes但文档不太有帮助:-(
谢谢
我以正常的方式创建了一个Rails引擎,安装了RSpec,并为模型生成了一个脚手架,但我无法通过任何路由规范.
这是一个例子:
describe Licensing::LicensesController do
it 'routes to #index' do
get('/licensing/licenses').should route_to('licensing/licenses#index')
end
end
Run Code Online (Sandbox Code Playgroud)
我正在虚拟应用程序中运行示例,如下所示:
$ cd spec/dummy
$ rake spec
/Users/brandan/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ../routing/licensing/licenses_routing_spec.rb
F
Failures:
1) Licensing::LicensesController routes to #index
Failure/Error: get('/licensing/licenses').should route_to('licensing/licenses#index')
No route matches "/licensing/licenses"
# /Users/brandan/repos/licensing/spec/routing/licensing/licenses_routing_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.04345 seconds
1 example, 1 failure
Run Code Online (Sandbox Code Playgroud)
引擎正确安装在虚拟应用程序中:
# spec/dummy/config/routes.rb
Rails.application.routes.draw do
mount Licensing::Engine => "/licensing"
end
Run Code Online (Sandbox Code Playgroud)
我可以进入虚拟应用程序并启动控制台并获得该路线就好了:
1.9.3p194 :001 > app.get('/licensing/licenses')
Licensing::License Load (0.3ms) SELECT "licensing_licenses".* FROM "licensing_licenses"
200 …Run Code Online (Sandbox Code Playgroud) 我有非常简单的形式,输入如下:
<input id="my_id" multiple="true" type="file" name="image_name[]" />
Run Code Online (Sandbox Code Playgroud)
现在我有两个问题:
我正在开发一个html5应用程序,我希望在写入随机位置8秒后,如果你已经赢了或没有一秒钟,那么它将从创建一个新的随机开始,我已经尝试过但是它do'esnt似乎做了什么,如果我写(真),浏览器崩溃.
有没有办法解决它?
jQuery(document).ready(function(){
ImageClicked = false;
for (var i=0;i<8;i++){
var XYScore = 0;
var RandomPlace=Math.floor((Math.random()*10)+1);
var Place;
var WantedXPr;
var WantedYPr;
switch(RandomPlace){
case 1:
Place="Berlin";
WantedYPr=790;
WantedXPr=4300;
break;
case 2:
Place="New York";
WantedYPr=1061;
WantedXPr=2345;
break;
case 3:
Place="barcelona";
WantedYPr=1049;
WantedXPr=4046;
break;
case 4:
Place="Johannesburg";
WantedYPr=2546;
WantedXPr=4618;
break;
case 5:
Place="shanghai";
WantedYPr=1272;
WantedXPr=6664;
break;
case 6:
Place="Moskau";
WantedYPr=732;
WantedXPr=4800;
break;
case 7:
Place="kahir";
WantedYPr=4690;
WantedXPr=1310;
break;
case 8:
Place="Delhi";
WantedYPr=1323;
WantedXPr=5707;
break;
case 9:
Place="rio de genero";
WantedYPr=2478;
WantedXPr=3050;
break;
case …Run Code Online (Sandbox Code Playgroud) 我正在尝试将无线电输入与指定的文本输入相关联。正如您在图片中看到的,有两个选项。我知道我可以使用for=""将标签与单选输入相关联,但是我如何将它与下面的文本输入相关联,反之亦然,所以当我专注于文本输入时,如果聚焦正确的单选按钮?

注意:输入的金额将被插入到数据库中,因此这是此表格中最重要的部分。目前,如果我点击 $Off,我仍然可以在 %Off 中输入一个数字。我不希望这种情况发生,因此用户不会感到困惑。
我的标记:
<div class="row-fluid control-group">
<div class="span7 pull-left">
<label class="radio" for="discount-dollars">
<input type="radio" name="discount" id="discount-dollars" value="dollars" checked="checked">
$ Off
</label>
<div class="input-append">
<input type="text" name="discount-dollars-amount" id="discount-dollars-amount" class="input-small dollars" placeholder="enter amount">
<span class="add-on">.00</span>
</div>
</div><!-- .span7 .pull-left -->
<div class="span5">
<label class="radio" for="discount-percent">
<input type="radio" name="discount" id="discount-percent" value="percent">
% Off
</label>
<input type="text" name="discount-percent-amount" id="discount-percent-amount" class="input-small percent" placeholder="enter amount" disabled="disabled">
</div>
</div><!-- .row-fluid .control-group -->
<script type="text/javascript">
$(function (){
$("form input[type=radio]").click(function (){
// get the …Run Code Online (Sandbox Code Playgroud) 鉴于以下代码,我应该在警报中看到什么?
var a = 100;
function afunc(infunc){
a = 10;
infunc.call();
}
afunc(function(){alert(a)});
Run Code Online (Sandbox Code Playgroud)
我最初的想法是我的浏览器应该提醒100,因为变量a = 100将作为作为afunc参数传递的匿名函数的范围.但是这假设匿名函数实际上是在全局上下文中定义的.显然情况并非如此,因为浏览器提醒10.那么为什么在范围链中a = 10之前a = 10?
谢谢!
在我的代码中,我有一个名称包含字符串'cache'的模型.例如:
class DataCache < ActiveRecord::Base
Run Code Online (Sandbox Code Playgroud)
而表名是data_caches.当我跑:
"data_caches".classify.constantize.new
Run Code Online (Sandbox Code Playgroud)
要初始化模型,我得到一个这样的错误:
NameError: uninitialized constant DataCach
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?我期待"DataCache",但得到了"DataCach".
我试图在我的Rails应用程序中使用select2,但是无法在我的视图中显示结果。我在Chrome浏览器控制台中看到了正确的json,但无法在下拉列表中显示结果...
请你帮助我好吗 ?
谢谢 :
控制器:
def friends
if params[:term]
@users = User.where{ ( (first_name =~ my{"%#{params[:term]}%"}) | (last_name =~ my{"%#{params[:term]}%"}) | ( ((first_name.op('||', ' ')).op('||',last_name)) =~ my{"%#{params[:term]}%"}) | ( ((last_name.op('||', ' ')).op('||',first_name)) =~ my{"%#{params[:term]}%"}) ) & ( adult==false ) }
end
respond_to do |format|
format.html
format.json { render :json =>{:results => @users.to_json(only: [:id, :first_name, :last_name]) }}
end
end
Run Code Online (Sandbox Code Playgroud)
我的Java语言:
$("#teen_search").select2({
placeholder: "Search for a teen",
minimumInputLength: 2,
ajax: {
url: "/friends.json",
dataType:'json',
data: function (search, page) {
return { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Rails从4.0.0升级到4.0.2,但是4.0.1中引入的更改破坏了我的应用程序.
这是我看到的错误:
undefined method `[]' for nil:NilClass
activerecord (4.0.2) lib/active_record/attribute_methods/read.rb:86:in `block in read_attribute'
activerecord (4.0.2) lib/active_record/attribute_methods/read.rb:84:in `fetch'
activerecord (4.0.2) lib/active_record/attribute_methods/read.rb:84:in `read_attribute'
activerecord (4.0.2) lib/active_record/attribute_methods/read.rb:59:in `__temp__6696273747f5e616d656'
app/models/player.rb:20:in `short_name'
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪开始的应用程序代码:
# app/models/player.rb
def short_name
self.class.where(first_name: first_name).where('id != ?', id).exists? ? name : first_name
end
Run Code Online (Sandbox Code Playgroud)
这是出现问题的差异(和Rails上的提交):
diff -r activerecord-4.0.0/lib/active_record/attribute_methods/read.rb activerecord-4.0.1/lib/active_record/attribute_methods/read.rb
[snip]
80,86c85,92
< column = @columns_hash.fetch(name) {
< return @attributes.fetch(name) {
< if name == 'id' && self.class.primary_key != name
< read_attribute(self.class.primary_key)
< end
< }
< }
---
> column …Run Code Online (Sandbox Code Playgroud) javascript ×3
jquery ×3
html ×2
datepicker ×1
datetime ×1
forms ×1
html5 ×1
input ×1
json ×1
models ×1
mongoid ×1
radio-button ×1
rspec-rails ×1
rspec2 ×1
scope ×1
textinput ×1