我的数据库中已经有以下两个迁移:
当我创造价格时:
class CreatePrices < ActiveRecord::Migration
def self.up
create_table :prices do |t|
t.string :price_name
t.decimal :price
t.date :date
t.timestamps
end
# add_index :prices (not added)
end
def self.down
drop_table :prices
end
end
Run Code Online (Sandbox Code Playgroud)
当我将一个user_id添加到价格时:
class AddUserIdToPrices < ActiveRecord::Migration
def self.up
add_column :prices, :user_id, :integer
end
# add_index :user_id (not added)
end
def self.down
remove_column :prices, :user_id
end
end
Run Code Online (Sandbox Code Playgroud)
有没有办法从命令行添加价格和user_id到索引?我看了这个问题,仍然对如何添加索引和我放"未添加"的部分感到困惑,因为它们是早期的迁移,因此它们容易出错.
我的问题是,为价格和user_id添加索引的最佳方式是什么?
感谢您的帮助!
我试图jquery ui autocomplete
在我的远程模式中实现它不起作用,而autocomplete
在常规静态页面上工作.
对于远程模态,我使用宝石的组合:modal-responder-rails和rails-bootstrap-modal
这是我的autocomplete
代码:
jQuery(function() {
var data = $('#book_subcategory_name').data('autocomplete-source');
var NoResultsLabel = "No Results";
return $('[id*="book_subcategory_name"]').autocomplete({
delay: 0,
position: {
my: "left+0 top+4"
},
source: function(request, response) {
var results = $.ui.autocomplete.filter(data, request.term);
if (!results.length) {
results = [NoResultsLabel];
}
response(results);
},
select: function (event, ui) {
if (ui.item.label === NoResultsLabel) {
event.preventDefault();
}
},
focus: function (event, ui) {
if (ui.item.label === NoResultsLabel) {
event.preventDefault();
}
}
}); …
Run Code Online (Sandbox Code Playgroud) 我可以将gem源重定向到我的Web服务器路径,在那里我将下载所有必需的gem包并放在那里吗?我想通过" bundle install
" 使用那些
GemFile将从http://rubygems.org获取那些在那里定义的那些.我经常得到一个错误,如"太多请求"(似乎是互联网拥塞问题).
是否可以将gem源路径重定向到我的本地服务器?
我正在尝试使用一些环境变量更新 ubuntu 中的 bashrc 文件。
我可以使用以下命令执行此操作。
echo 'export APP=/opt/tinyos-2.x/apps' >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
但我想手动完成,这意味着用 vim 编辑器打开文件然后添加它。这里的问题是,当我打开 bashrc 文件时,结束行是“fi”,当我到达那里并按插入然后输入以转到新行时,它保持在同一行并仅移动 fi 字或创建 A 或 C或 B 个随机字符。
我可以知道一些命令来处理这个 bashrc 文件,以便我可以添加一个新行,然后在那里添加我的变量吗?
我试过在网上看,但没有找到我要找的东西。
在我的测试中,我试图点击etsy.com,进行搜索,点击结果,然后将项目添加到我的购物车.我可以做任何事情,直到我尝试点击"添加到购物车"按钮.下面的代码实际上在IRB中工作,所以我知道我的定位器是可靠的,但是当我运行测试时,我得到一个元素在点错误时无法点击
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/response.rb:71:in 'assert_ok': unknown error: Element is not clickable at point (930, 586) (Selenium::WebDriver::Error::UnknownError)
(Session info: chrome=61.0.3163.100)
这是我的考试
require 'watir'
# test that a user can search for and add an item to shopping cart
b = Watir::Browser.new :chrome
begin
b.goto "http://etsy.com"
b.text_field(:id => 'search-query').set 'bacon is my spirit animal coaster'
b.button(:value => 'Search').present?
b.button(:value => 'Search').click
b.p(:text => /Bacon Spirit Animal Coaster/).click
b.select_list(:id => 'inventory-variation-select-0').option(:text => 'Single ($8.00)').select
b.button(:text => /Add to cart/).click
if b.text.include?("item in your cart")
puts …
Run Code Online (Sandbox Code Playgroud) 我需要运行一个作业,在设置比赛的字段时向用户发送电子邮件published_at
.所以我有一个Contest
模型和一个运行工作的方法:
class Contest < ApplicationRecord
after_create :send_contest
private
def send_contest
SendContestJob.set(wait: 30.minutes).perform_later(self)
end
end
Run Code Online (Sandbox Code Playgroud)
但是即使published_at
字段是空白的,工作也会运行.验证要存在的字段不是一个选项,因为published_at
可以稍后设置.那么有什么解决方案如何在设置字段后运行作业?谢谢你.