如何在Rails控制台上打印表单?

时间:2017-09-21 20:40:21

标签: ruby-on-rails

我正在尝试调试日期字段。我收到以下错误。如何从控制台打印表单和表单助手?

irb(main):014:0> p
=> #<Principal id: 1, company_id: 31, name: "Jim", title: "CMO", address: "Seattle, WA", ssn: "1112223333", dob: "1970-01-01", created_at: "2017-09-21 20:07:31", updated_at: "2017-09-21 20:07:31">
irb(main):015:0> helper.form_for p do |pf|
irb(main):016:1* end
NoMethodError: undefined method `polymorphic_path' for #<ActionView::Base:0x00000009c3d878>

1 个答案:

答案 0 :(得分:1)

在rails 5中,你可以使用ActionController::Renderer,如下所示:

form = ApplicationController.render inline:<<-FORM
  <%= form_for MyResource.new do |form| %>
  <% end %>
FORM

puts form
# => <form class="new_my_resource" id="new_my_resource" action="/my_resources" accept-charset="UTF-8" method="post">
#      <input name="utf8" type="hidden" value="&#x2713;" />
#      <input type="hidden" name="authenticity_token" value="..." />
#    </form>