我正在使用PDFKit(使用wkhtmltopdf)尝试在Rails 3应用程序中将视图呈现为pdf.
PDFKit通过Errno::EPIPE (Broken pipe)指向send_data(kit.to_pdf, :filename => "generated.pdf", :type => 'application/pdf')我的控制器show动作呈现:
# Controller
def show
respond_to do |format|
format.html { render }
format.pdf do
html = render_to_string(:layout => false , :action => "show.html.haml")
kit = PDFKit.new(html)
send_data(kit.to_pdf, :filename => "invoice.pdf", :type => 'application/pdf')
return # to avoid double render call
end
end
end
# Gemfile
...
gem 'pdfkit'
gem 'wkhtmltopdf'
...
Run Code Online (Sandbox Code Playgroud)
我知道wkhtmltopdf不是这个错误的来源,因为wkhtmltopdf public/404.html tmp/404.pdf从Rails.root工作中如预期的那样.
在使用中间件失败后,我正在使用jonathanspies.com中的一个示例 …
我有三个模型以多模型形式呈现.
class Parent < ActiveRecord::Base
has_many :children
accepts_nested_attributes_for :children
end
class Child < ActiveRecord::Base
belongs_to :parent
has_many :other_children
accepts_nested_attributes_for :other_children
end
class OtherChild < ActiveRecord::Base
belongs_to :child
end
= form_for @parent do |f|
# fields for parent
= f.fields_for :children, @parent.children do |cf|
= cf.fields_for :other_children, @parent.children do |ocf|
# fields_for other child
= cf.fields_for :other_children, @parent.children.new do |ocf|
# fields_for other child
Run Code Online (Sandbox Code Playgroud)
这有效,除非我通过jquery复制第二组子字段.更清楚的是,带有新的other_child模型的fields_for有一个创建按钮,可以触发一些jquery,例如$(new_child_form).clone().insertBefore($(new_child_form))允许在同一个表单提交中添加多个子模型.我知道我可以通过ajax单独提交每个子表单,但这不是我想要的.
Rails越来越多parent[children_attributes][0][other_children_attributes][1],似乎只使用最后一个.有任何想法吗?
我需要通过capistrano将Rails应用程序部署到远程Intranet上的服务器.例如,如果我要ssh到目标服务器,它看起来像:
localhost$ ssh server1
server1$ ssh server2
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗?
提前致谢.
给一张桌子账单
# bills
id | name | amount | user_id
1 | jumper | 100 | 1
2 | gopper | 200 | 1
3 | jumper | 150 | 2
4 | blobber | 300 | 3
Run Code Online (Sandbox Code Playgroud)
和一个表用户
# users
id | name
1 | John Doe
2 | Mike Marley
3 | Bill Mickane
Run Code Online (Sandbox Code Playgroud)
当我执行查询时
select * from bills where user_id in (1,2) order by name, amount desc
Run Code Online (Sandbox Code Playgroud)
我得到
# bills
id | name | amount | user_id …Run Code Online (Sandbox Code Playgroud) form_for帮助器似乎不适用于Rails 3.我正在尝试为模型及其子模型构建表单.
class Person < ActiveRecord::Base
has_one :address
end
class Address < ActiveRecord::Base
belongs_to :person
end
Run Code Online (Sandbox Code Playgroud)
在早期版本的rails中,我将构建如下形式:
-# Haml
- form_for @person do |f|
... (person fields here)
- f.fields_for @person.address do |address_f|
... (address fields here)
Run Code Online (Sandbox Code Playgroud)
我怎么能在Rails 3中这样做?