0

我的应用程序中有密码更新。我必须从其他控制器调用相同的表单。我添加了相同的表单,但它给了我错误未定义的局部变量或方法“资源”。如何从任何其他控制器调用更新密码?我的表格是这样的:

<%= simple_form_for(resource, as: resource_name, url: update_password_registrations_path(resource), html: { method: :put }, remote: true) do |f| %>
  <div class="form-inputs">
  <%= f.input :current_password, required: true, wrapper: :prepend, error: true do %>
    <span class="add-on"><i class="ss-icon ss-key"></i></span>
    <%= f.input_field :current_password, placeholder: "Old Password" %>
  <% end %>
  <%= f.input :password, required: true, wrapper: :prepend, error: true do %>
      <span class="add-on"><i class="ss-icon ss-key"></i></span>
      <%= f.input_field :password, placeholder: "New Password" %>
  <% end %>
  <%= f.input :password_confirmation, required: true, wrapper: :prepend, error: true do %>
        <span class="add-on"><i class="ss-icon ss-key"></i></span>
        <%= f.input_field :password_confirmation, placeholder: "New Password Confirmation" %>
  <% end %>
</div>
  <%= f.button :submit, "Update", class: "btn btn-primary" %>
<% end %>
4

1 回答 1

1

你的资源就是你所谓的设计资源。所以它可能是用户。

代替

<%= simple_form_for(resource, as: resource_name, url: update_password_registrations_path(resource), html: { method: :put }, remote: true) do |f| %>

<%= simple_form_for(@user, url: update_password_registrations_path(@user), html: { method: :put }, remote: true) do |f| %>

确保您@user在控制器中设置。如果它是当前用户的表单,您可以替换@usercurrent_user.

于 2013-10-10T10:53:38.483 回答