导轨 5.1
我有一个使用 PostgreSQL 作为数据库的 RAILS 应用程序。我想从 RAILS 的角度导出/转储 RAILS 数据库数据。所以我独立于数据库。后来我想使用这个导出/转储文件将数据加载/导入/播种回数据库。
我尝试了以下 GEM:
seed_dump
可以用,但是不能处理HABTM 模型关系。
yaml_db,它有效,但 yaml 格式不是rails db:seed理解的格式
我想使用 GROVER 从我的应用程序中将相同的 ERB/HTML 页面导出为 PDF。它可以工作,但生成的 PDF 似乎缺少样式和格式,似乎没有处理 CSS。
这是我在控制器中的代码:
html_string = render_to_string(
{
template: 'users/show.html.erb',
locals: { id: params[:id] }
})
pdf = Grover.new(html_string, format: 'A4').to_pdf
respond_to do |format|
format.html
format.pdf do
send_data(pdf, disposition: 'inline', filename: "Show_ID_#{params[:id]}", type: 'application/pdf')
end
end
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何说服 GROVER 也处理 CSS 文件?
我有一个属于 LoadingStation 模型的订单模型。并且 LoadingStation 将在 Order 表中使用两次,所以它看起来像:
class CreateLoadingStations < ActiveRecord::Migration[5.0]
def change
create_table :loading_stations do |t|
t.integer :type
t.string :comp_name1
t.string :street
t.string :street_num
t.string :zip_code
t.string :city
t.timestamps
end
end
end
class CreateOrders < ActiveRecord::Migration[5.0]
def change
create_table :orders do |t|
t.string :status
t.belongs_to :loading_station, class_name: "LoadingStation", index: true, foreign_key: "loading_station_id"
t.belongs_to :unloading_station, class_name: "LoadingStation", index: true, foreign_key: "unloading_station_id"
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行Rails db:migrate时,出现以下错误: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: 关系“unloading_stations”不存在
嗯嗯,似乎没有正确检测到 class_name。两个语句中的 class_name 应该相同,对吗?
让我们检查一下装载站的型号:
class LoadingStation …Run Code Online (Sandbox Code Playgroud) 我想使用Where-Object限制输出Get-PSDrive仅限于网络共享.
Get-PSDrive 告诉我以下内容:
Name Used (GB) Free (GB) Provider Root CurrentLocation ---- --------- --------- -------- ---- --------------- A FileSystem A:\ Alias Alias C 16.19 43.47 FileSystem C:\ Users\HansB\Documents Cert Certificate \ D FileSystem D:\ Env Environment Function Function HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE V 451.39 159.76 FileSystem \\192.168.71.31\fs_log_target Variable Variable W 197.72 FileSystem \\192.168.71.32\perf200 WSMan WSMan X 197.72 FileSystem \\192.168.71.32\perf100 Y 271.52 34.33 FileSystem \\192.168.71.30\group200 Z 271.52 34.33 FileSystem \\192.168.71.30\group100
然后我想获得\\192.168.71.30\group100网络共享:
Get-PSDrive | …Run Code Online (Sandbox Code Playgroud)