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

时间:2022-01-09 20:47:23

I'm trying to debug a date field. I'm getting the following error. How do I print a form and form helpers from the console?

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

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 个解决方案

#1


1  

In rails 5 you can use ActionController::Renderer like so:

在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>

#1


1  

In rails 5 you can use ActionController::Renderer like so:

在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>