如何:title在我的模型中验证,以便只接受字母az,Az和0-9?
validates :title, :format => { with: REGULAR EXPRESSION , :message => 'no special characters, only letters and numbers' }
Run Code Online (Sandbox Code Playgroud)
正则表达式应该是什么?
我需要帮助完成使用该rails g migration命令将数组列添加到资源的步骤.我有一个postgresql数据库.我需要创建一个字符串数组和另一个整数数组.我想要它,以便在我的schema.rb文件中我有......
create_table "streams", force: true do |t|
t.array "ids" #strings
t.array "lengths" #integers
Run Code Online (Sandbox Code Playgroud) 我试图了解如何使用发条执行自定义代码.这是lib/clock.rbHeroku在其devcenter文档中使用的示例文件.
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'
include Clockwork
every(4.minutes, 'Queueing interval job') { Delayed::Job.enqueue IntervalJob.new }
every(1.day, 'Queueing scheduled job', :at => '14:17') { Delayed::Job.enqueue ScheduledJob.new }
Run Code Online (Sandbox Code Playgroud)
什么是IntervalJob和ScheduledJob?这些文件应该放在哪里?我想运行自己的自定义作业,可以访问我的数据库记录.
编辑
这是我的 /lib/clock.rb
require 'clockwork'
require './config/boot'
require './config/environment'
module Clockwork
handler do |job|
puts "Running #{job}"
end
every(2.minutes, 'Filtering Streams') { Delayed::Job.enqueue FilterJob.new}
end
Run Code Online (Sandbox Code Playgroud)
这是我的 /lib/filter_job.rb
class FilterJob
def perform
@streams = Stream.all
@streams.each do |stream|
# manipulating stream properties
end
end
end
Run Code Online (Sandbox Code Playgroud)
我收到错误:
uninitialized constant …Run Code Online (Sandbox Code Playgroud) 我想拆分一个字符串并保存在另一个段之后发生的段.例如
http://www.youtube.com/channel/xxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
如何保存之后出现的片段http://www.youtube.com/channel/,保存xxxxxx部分?
ruby ×2
arrays ×1
clockwork ×1
heroku ×1
migration ×1
postgresql ×1
regex ×1
split ×1
string ×1
validation ×1