当我将_form.haml partial复制到_edit_form.haml partial并替换为“_form”时,在我的edit.haml中使用“_edit_form”我得到了奇怪的错误(也许这并不奇怪,我只是无法理解原因)。< / p>
wrong number of arguments (0 for 1)
Extracted source (around line #1):
1: = form.label :email
2: %br
3: = form.text_field :email
4: %br
.../app/views/users/_edit_form.haml:1:in `form'
.../app/views/users/_edit_form.haml:1:in `_run_haml_app47views47users47_edit_form46haml_locals_edit_form_object'
.../app/views/users/edit.haml:5:in `_run_haml_app47views47users47edit46haml'
.../app/views/users/edit.haml:3:in `_run_haml_app47views47users47edit46haml'
这是edit.haml:
%h1 Edit My Account
- form_for @user, :url => account_path do |f|
= f.error_messages
= render :partial => "edit_form", :object => f
= f.submit "Update"
%br
= link_to "My Profile", account_path
...和edit_form.haml
= form.label :email
%br
= form.text_field :email
%br
%br
= form.label :old_password, "Old password"
%br
= form.password_field :old_password
%br
%br
= form.label :password, "Change password"
%br
= form.password_field :password
%br
%br
= form.label :password_confirmation
%br
= form.password_field :password_confirmation
%br
我无法理解问题出在哪里。因为它适用于_form.haml
diff _form.haml _edit_form.haml
1c1
< = form.label :login
---
> = form.label :email
3c3
< = form.text_field :login
---
> = form.text_field :email
6c6
< = form.label :email
---
> = form.label :old_password, "Old password"
8c8
< = form.text_field :email
---
> = form.password_field :old_password
11c11
< = form.label :password, form.object.new_record? ? nil : "Change password"
---
> = form.label :password, "Change password"
答案 0 :(得分:2)
:object
隐式地在partial中公开为partial的名称。 <{1}}中将form
更改为edit_form
,它应该有效。