我正在尝试使用 papertrail 将模型的更改事件记录在单独的数据库中。
我正在使用 Rails 4.1.2
红宝石2.1
纸迹 4.0.0
下面是我在关注中添加的代码
module Foo
class Base < ActiveRecord::Base
end
class Version < Base
include PaperTrail::VersionConcern
end
class Topic < Base
has_paper_trail class_name: 'Foo::Version'
end
end
Foo::Base.establish_connection(:trail_development)
Run Code Online (Sandbox Code Playgroud)
我已将这个 Foo 包含在 topic.rb 中
class Topic < ActiveRecord::Base
include Foo
end
Run Code Online (Sandbox Code Playgroud)
当我尝试创建、编辑或删除主题时,这不起作用。
我在烧瓶应用中使用芹菜,但芹菜(3.1.8).这是我的烧瓶应用配置
celery.py
from __future__ import absolute_import
from celery import Celery
from cuewords.settings import CELERY_BROKER_URL,CELERY_RESULT_BACKEND
app = Celery('proj',
broker=CELERY_BROKER_URL,
backend=CELERY_RESULT_BACKEND)
app.conf.update(CELERY_TASK_RESULT_EXPIRES=3600)
if __name__ == '__main__':
app.start()
Run Code Online (Sandbox Code Playgroud)
setting.py
CELERY_BROKER_URL='redis://localhost:6379/0'
CELERY_RESULT_BACKEND='redis://localhost:6379/0'
BROKER_TRANSPORT = 'redis'
Run Code Online (Sandbox Code Playgroud)
api.py
class Webcontent(Resource):
def post(self,session=session):
args = self.parser.parse_args()
site_url = args["url"]
url_present=Websitecontent.site_url_present(session,site_url)
if site_url.strip() != "" and not url_present:
try:
#add data and commit
session.commit()
websitecontent=Websitecontent(params*)
websitecontent.update_url(id,session)
except:
session.rollback()
raise
finally:
session.close()
else:
return "No data created / data already present"
Run Code Online (Sandbox Code Playgroud)
在我的模型中,我正在添加一个方法来完成任务
model.py
from cuewords.celery import app
class Websitecontent(Base): …Run Code Online (Sandbox Code Playgroud) 我正在编写一个脚本来从 Rails 项目的 gemfile 中获取所有 gem。脚本是这样的
@gem_file_path=File.expand_path('../Gemfile', __FILE__) || ENV['BUNDLE_GEMFILE'] || Dir.pwd + "/Gemfile"
File.open(gem_file_path).read.each_line do |i|
i=i.split
if i[0] == "gem" && i[0].start_with?("gem")
name = i[1].gsub(",","")
gem_name= eval name
author_email_id=Gem::Specification.find_by_name(gem_name.to_s).email
author_name=Gem::Specification.find_by_name(gem_name).author
end
end
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?因为当 gemfile 和其他可能性中提到类似下面的内容时,我也会遇到问题
gem 'rspec-rails',:group => [:test,:development]
Run Code Online (Sandbox Code Playgroud)
谢谢