我正在使用Product以下列[id, name, CategoryId]和Category表的表[id, name]
产品型号: -
module.exports = function(sequelize, DataTypes) {
var Product = sequelize.define('Product', {
name: DataTypes.STRING
}, {
associate: function(models) {
Product.belongsTo(models.Category);
}
});
return Product
}
Run Code Online (Sandbox Code Playgroud)
分类型号: -
module.exports = function(sequelize, DataTypes) {
var Category = sequelize.define('Category', {
name: { type: DataTypes.STRING, allowNull: false }
}, {
associate: function(models) {
Category.hasMany(models.Product, { onDelete: 'cascade' });
}
});
return Category
}
Run Code Online (Sandbox Code Playgroud)
当我删除类别时,它只删除类别而不删除与之关联的相应产品.我不知道为什么会这样?
更新:Sequelize版本 sequelize 1.7.0
================================================== ============================== 答案(我如何修复.): -
我做到了这一点通过增加使用数据库约束 …
美国东部时间上午04:00的下一次出现的有效方法是什么?
例如,如果日期和时间是2013/11/19 01:30:00,那么下次发生的时间是2013/11/19 04:00:00,不过如果是2013/11/19 17:00:00那么下次发生的时间是2013/11/20 04:00:00
我正在运行Rails 4.0.1和Ruby 2.0.0.我目前有一个graph.js,它从用户那里获取一个储蓄计算器的输入,以便用d3和rickshaw.js图创建一个图形.
我的graph.js文件保存在app/assets/javascripts/graph.js.我打电话给人力车图
var graph = new Rickshaw.Graph()
Run Code Online (Sandbox Code Playgroud)
我收到了错误 Uncaught ReferenceError: Rickshaw is not defined.
该rickshaw.js文件vendor/javascript/rickshaw.js与d3.layout.js和一起保存d3.vs.js.如果我保存所有这些文件在app/assets/javascripts一切正常,但这似乎不是正确的rails方式.
有谁知道如何解决这个错误?
谢谢.
我正在研究Belongs_to协会,我使用了以下模型,因为每个订单都属于客户,所以我使用了belongs_to的顺序模型,它在创建订单时给出了错误
未命名的方法`orders'for#
当我在客户模型中使用has_many:orders时,它工作正常,为什么它只与belongs_to一起使用
它使用has_many:客户模型中的订单而不是has_one:客户控制器中的订单它给出了相同的上述错误.
提前致谢.
型号: - order.rb
class Order < ActiveRecord::Base
belongs_to :customer
attr_accessible :order_date, :customer_id
end
Run Code Online (Sandbox Code Playgroud)
型号: - customer.rb
class Customer < ActiveRecord::Base
attr_accessible :name
end
Run Code Online (Sandbox Code Playgroud)
控制器: - orders.rb
def create
@customer = Customer.find_by_name(params[:name])
@order = @customer.orders.new(:order_date => params[:orderdate] )
respond_to do |format|
if @order.save
format.html { redirect_to @order, notice: 'Order was successfully created.' }
format.json { render json: @order, status: :created, location: @order }
else
format.html { render action: "new" }
format.json { render json: @order.errors, status: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Active Admin,有没有办法覆盖 Active admin 主题使用的 CSS?
例如:- 我必须将禁用的提交按钮的 css 更改为光标:等待;并使其不可点击。
最好的方法是什么?
我的文本包含‍ 零宽度连接符,该连接符在 UI 中不可见,但是当我将其作为短信发送时,它?在 iPhone 中显示为问号。
我尝试使用 gsub 删除它,但它没有被删除。
text.gsub("&zwj\;", "")
Run Code Online (Sandbox Code Playgroud)
有什么办法可以从文本中删除这种不可见的字符吗?
更新:
除了@matt的回答
Unicode 具有以下零宽度字符:
要在文本中替换它们,您可以使用简单的正则表达式:
text = text.gsub(/[\u200B-\u200D\uFEFF]/, '')
Run Code Online (Sandbox Code Playgroud) 刚刚将 Active Admin 添加到我的项目中。我想从显示页面隐藏编辑和删除操作,并且编辑和删除操作应该出现在索引页面中。
有一个更好的方法吗?提前致谢。
我正在使用Select2 4.0.1,我已经使用 ajax 根据用户输入填充结果,但是每当我搜索任何内容时都会select2列出第一页结果,但没有加载连续页面,也会在滚动时请求第二页。似乎我错过了一些东西。
$multiselect = $(element).select2({
closeOnSelect: false,
multiple: true,
placeholder: 'Assign a new tag',
tags: true,
tokenSeparators: [","],
ajax: {
url: '/search_url',
dataType: 'json',
type: 'GET',
delay: 250,
data: function(params) {
return {
search: params.term,
page: params.page
};
},
processResults: function(data, params) {
var more, new_data;
params.page = params.page || 1;
more = {
more: (params.page * 20) < data.total_count
};
new_data = [];
data.items.forEach(function(i, item) {
new_data.push({
id: i.name,
text: i.name
});
}); …Run Code Online (Sandbox Code Playgroud) 我正在CKEditor我的应用程序中实现。当我尝试实例化CKEditor到 textarea 时,出现以下错误
Cannot read property 'getSelection' of undefined
Run Code Online (Sandbox Code Playgroud)
在 ckeditor 的下面一行
getNative: function() {
return void 0 !== this._.cache.nativeSel ? this._.cache.nativeSel : this._.cache.nativeSel = B ? this.document.$.selection : this.document.getWindow().$.getSelection() }
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢。
我正在用一些动态的月份更改DateTime的月份.
我用了 DateTime.now.change(month: month)
仅当月值来自[1,3,5,7,8,10,12]时才有效
当我尝试使用[2,4,6,9,11]时,它会返回ArgumentError: invalid date错误
irb(main):073:0> DateTime.now.change(month: 1)
=> Sat, 31 Jan 2015 19:59:28 +0530
irb(main):075:0> DateTime.now.change(month: 3)
=> Tue, 31 Mar 2015 19:59:33 +0530
irb(main):077:0> DateTime.now.change(month: 5)
=> Sun, 31 May 2015 19:59:39 +0530
irb(main):079:0> DateTime.now.change(month: 7)
=> Fri, 31 Jul 2015 19:59:44 +0530
irb(main):080:0> DateTime.now.change(month: 8)
=> Mon, 31 Aug 2015 19:59:48 +0530
irb(main):082:0> DateTime.now.change(month: 10)
=> Sat, 31 Oct 2015 19:59:54 +0530
irb(main):084:0> DateTime.now.change(month: 12)
=> Thu, 31 Dec 2015 20:00:00 +0530 …Run Code Online (Sandbox Code Playgroud) 我有一个下拉菜单。我希望水豚浏览它并找到特定元素并单击它。我目前正在尝试执行一个 inside 子句,并让它遍历列表并找到这个元素:“Cow_poop”
<div class="ant-select-selection ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="7256666c-da5f-48d6-c8fc-a249a4ed0fc9" aria-expanded="false" tabindex="0">
<div class="ant-select-selection__rendered">
<div class="ant-select-selection-selected-value" title="cow_poop" style="display: block; opacity: 1;">cow_poop</div>
<div class="ant-select-search ant-select-search--inline" style="display: none;">
<div class="ant-select-search__field__wrap">
<input autocomplete="off" class="ant-select-search__field" value="">
<span class="ant-select-search__field__mirror"> </span>
</div>
</div>
</div>
<span class="ant-select-arrow" unselectable="on" style="user-select: none;">
<i aria-label="icon: down" class="anticon anticon-down ant-select-arrow-icon">
<svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true">
<path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path>
</svg>
</i> …Run Code Online (Sandbox Code Playgroud) ruby ×5
activeadmin ×2
datetime ×2
javascript ×2
ajax ×1
associations ×1
belongs-to ×1
capybara ×1
ckeditor ×1
css ×1
jquery ×1
node.js ×1
rspec ×1
selenium ×1
sequelize.js ×1
string ×1