0

我为设计注册表单创建了自定义表单生成器。

表单看起来像这样,并且工作正常:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), builder: BootstrapFormBuilder) do |f| 
  <%= f.text_field :username, :autofocus => true %>
  <%= f.email_field :email %>
  <%= f.password_field :password %>
  <%= f.password_field :password_confirmation %>

  <%= f.submit "Sign up", class: "btn btn-default" %>
<% end %>

现在我想创建名为bootstrap_form_for. 在我写的应用程序助手中(只是为了测试它):

module ApplicationHelper
  def bootstrap_form_for(record, options = {}, &block)
    form_for(record, options = {}, &block)
  end
end

form_for我插入而不是bootstrap_form_for我得到错误:undefined method 'users_path' for #<#<Class:0x007f9eb40bc728>:0x007f9eb40bb9b8>在这一bootstrap_form_for行。

错误页面标题:NoMethodError in Devise::Registrations#new

你知道为什么吗?

4

1 回答 1

0

问题在这里:

module ApplicationHelper
  def bootstrap_form_for(record, options = {}, &block)
    form_for(record, options = {}, &block)
  end
end

它应该是:

module ApplicationHelper
  def bootstrap_form_for(record, options = {}, &block)
    form_for(record, options, &block)
  end
end
于 2013-10-08T09:40:02.173 回答