我正在尝试使用wkhtmltopdf生成的PDF中使用自定义字体.我读到你不能使用谷歌webfonts和wkhtmltopdf使用truetype .ttf文件.任何人都可以证实吗?所以我从google webfont下载了一个.ttf文件并放入我的服务器,然后使用了字体:
@font-face {
font-family: Jolly;
src: url('../fonts/JollyLodger-Regular.ttf') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
和字体系列:
<style type = "text/css">
p { font-family: 'Jolly', cursive; }
</style>
Run Code Online (Sandbox Code Playgroud)
现在,应该使用Jolly Lodger字体呈现的文本根本不显示,页面为空白.
我究竟做错了什么?
PS:我试过不同的.ttf文件.
我一直在尝试使用rails的缓存功能,但我无法使一些缓存片段过期,尽管它们似乎已过期.使用rails教程网站中指出的"俄罗斯娃娃缓存",我正在使用此配置
<% cache "all_available_releases" do %>
<% @releases.each do |release| %>
<% cache(release) do %>
<html code with>
<%ruby code @release.name blah blah blah%>
<%end%>
<%end%>
<%end%>
Run Code Online (Sandbox Code Playgroud)
我使用release_controller.rb控制器中的外部缓存到期,我使用expire_fragment("all_available_releases")来使片段到期.我在控制器的每个更新或删除或添加条目的方法中使用它.
这是WEBrick的日志,虽然expire片段已经注册,但5行之后读取并使用过期片段,而不应该.此示例是在销毁调用之后.
Processing by ReleasesController#destroy as HTML
Parameters: {"authenticity_token"=>"***/***/********************+********=", "id"=>"2"}
Release Load (0.1ms) SELECT "releases".* FROM "releases" WHERE "releases"."id" = ? LIMIT 1 [["id", "2"]]
(0.1ms) begin transaction
SQL (2.0ms) DELETE FROM "releases" WHERE "releases"."id" = ? [["id", 2]]
(148.0ms) commit transaction
Expire fragment views/all_available_releases (0.1ms)
Redirected to http://127.0.0.1:3000/releases
Completed 302 Found in …Run Code Online (Sandbox Code Playgroud) 这是一个常见的问题,但没有一个答案似乎可以解决这个问题.我得到通常的:You have already activated rack 1.4.1, but your Gemfile requires rack 1.3.6. Using bundle exec may solve this.
清除Gemlock文件什么都没做,bundle install再次运行bundle install --binstubs没有做任何事情......运行没有解决问题,因为从你的应用程序根"运行./bin/{rake|rails|etc"只是造成了更多的错误.有没有办法解决这个看似常见的问题?
我想让工厂女孩在我的rails 4.1.1 app中使用rspec运行.
问题是当我rspec在命令行中运行时,我得到了Failure/Error: verse = build(:verse) ArgumentError: Factory not registered: verse.
我很遗憾,因为我检查了工厂女孩入门页面,这里的许多答案在SO和我仍然无法解决这个问题.
在我的Gemfile中:
gem 'rails', '4.1.1'
group :development, :test do
gem 'rspec-rails'
gem "factory_girl_rails"
end
Run Code Online (Sandbox Code Playgroud)
我的spec_helper.rb文件:
require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
Run Code Online (Sandbox Code Playgroud)
规格/控制器/ API/verses_controller_spec.rb
describe "API Controller" do
describe "show a verse" do
it "should return status 200" do
verse = build(:verse)
get :show, id: verse.id
expect(response).to have_http_status(200)
end
it "should return json object" do
verse = build(:verse)
get :show, id: verse.id
JSON.parse(response.body).should …Run Code Online (Sandbox Code Playgroud) 我想让我的bootstrap模式使用ajax检索数据:
<a href="{{ path('ajax_get_messages', { 'superCategoryID': 35, 'sex': sex }) }}" data-toggle="modal" data-target="#birthday-modal">
<img src="{{ asset('bundles/yopyourownpoet/images/messageCategories/BirthdaysAnniversaries.png') }}" alt="Birthdays" height="120" width="109"/>
</a>
Run Code Online (Sandbox Code Playgroud)
我的模态:
<div id="birthday-modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Birthdays and Anniversaries</h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">Close</a>
{#<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>#}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,会显示模态但是正文是空的.此外,我没有看到任何ajax请求.我正在使用Bootstrap 2.1.1
我究竟做错了什么?
这最近引起了一些挫折......
似乎在我的黄瓜测试中使用工厂,在某些情况下会导致AssociationTypeMismatch错误,例如:
MyModel(#65776650)期待,得到MyModel(#28190030)(ActiveRecord :: AssociationTypeMismatch)
当存在关联引用时,似乎会发生这些 - 就好像Factory创建的对象与实际对象不同.有关更多详细信息,请参阅此问题:Cucumber重复类问题:AssociationTypeMismatch
我一直在逐步将Factory调用更改为真正的Model.create或mock_model调用.继续使用工厂女孩会很好......我想知道是否有什么我可能做错了?
谢谢
我正在尝试使用查询构建器来选择属于某个superCategory的所有类别(category和superCategory具有多对多的关系).但是,我无法构建正确的查询构建器句子,因为我不知道如何引用我的类别中的superCategory,因为我的类别ID中没有superCategory字段.
数据库中的对象如下所示:
Category:
id
name
SuperCategory
id
name
categories_superCategories
id
category_id
superCategory_id
Run Code Online (Sandbox Code Playgroud)
以下是我的对象(yml文件)的定义:
YOP\YourOwnPoetBundle\Entity\TraitCategory:
type: entity
repositoryClass: YOP\YourOwnPoetBundle\Repository\TraitCategoryRepository
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: '255'
lifecycleCallbacks: { }
manyToMany:
superCategories:
targetEntity: SuperCategory
joinTable:
name: traitCategories_superCategories
joinColumns:
traitCategory_id:
referencedColumnName: id
inverseJoinColumns:
superCategory_id:
referencedColumnName: id
Run Code Online (Sandbox Code Playgroud)
和
YOP\YourOwnPoetBundle\Entity\SuperCategory:
type: entity
repositoryClass: YOP\YourOwnPoetBundle\Repository\SuperCategoryRepository
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: '255'
lifecycleCallbacks: { }
manyToMany:
msgCategories:
targetEntity: …Run Code Online (Sandbox Code Playgroud) 我正在使用Symfony2.0和FOSUserBundle,并希望在我的登录表单上禁用csrf令牌.
我已经在我的config.yml网站上全局禁用了csrf保护:
framework:
csrf_protection:
enabled: false
Run Code Online (Sandbox Code Playgroud)
这很好用,我的表单中没有添加csrf字段.但是,这不适用于登录表单.仅在此表单上,如果我在表单中不包含令牌,则会收到"无效的CSRF令牌"错误:
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
Run Code Online (Sandbox Code Playgroud)
如何在登录表单上禁用CSRF令牌?
当模型无法检索记录时,我的应用程序正在将ActiveRecord :: RecordNotFound传播到控制器.
这是数据库查询:
def self.select_intro_verse
offset = rand(IntroVerse.count)
IntroVerse.select('line_one', 'line_two', 'line_three', 'line_four', 'line_five').offset(offset).first!.as_json
end
Run Code Online (Sandbox Code Playgroud)
first!ActiveRecord::RecordNotFound如果没有找到记录,则引发一个,我可以拯救它并在我的控制器中渲染一个合适的模板.
这是预期的行为,所以我想在我的规格中对它进行测试.我写:
context "verses missing in database" do
it "raises an exception" do
expect(VerseSelector.select_intro_verse).to raise_exception
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行rspec时:
1) VerseSelector verses missing in database raises an exception
Failure/Error: expect(VerseSelector.select_intro_verse).to raise_exception
ActiveRecord::RecordNotFound:
ActiveRecord::RecordNotFound
对我来说,即使异常被提出,测试也会失败!我怎样才能通过考试?
如何使用prawn gem在PDF表格中设置字体大小?
当我给大虾打电话时如下:
pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
pdf.table data,
:header => true,
:column_widths => widths,
:font_size => 7,
:row_colors => ["EEEEEE", "FFFFFF"]
Run Code Online (Sandbox Code Playgroud)
我得到一个NoMethodError
undefined method `font_size=' for #<Prawn::Table:0x6ce37ea4>
Run Code Online (Sandbox Code Playgroud)
当我删除":font_size => 7"时,它呈现但我得到了不合需要的字体大小.
我使用的是大虾0.12.0,ruby 1.9.3p194和Rails 3.1.9.
factory-bot ×2
rspec ×2
ruby ×2
activerecord ×1
caching ×1
csrf ×1
css ×1
cucumber ×1
doctrine-orm ×1
fonts ×1
jquery ×1
login ×1
modal-dialog ×1
php ×1
prawn ×1
rack ×1
symfony ×1
symfony-2.0 ×1
wkhtmltopdf ×1