我有一个表单,对于布局(以及将来使用),我想知道如何更改生成的默认f.submit:
到一个不应该出错的html标签。
我现在拥有的是对formbuilder的扩展
在我看来:
<%= form_for resource, :as => resource_name, :url => session_path(resource_name), :class => "form with-margin", :builder => AppFormBuilder do |f| %>
...
<%= f.submit %>
<% end %>
在我的lib / appformbuilder中:
class AppFormBuilder < ActionView::Helpers::FormBuilder
def submit(text, options = {})
options[:type] = "submit"
@template.content_tag(:button, text, options)
end
end
但这给了我一个错误:
NameError in Devise/sessions#new
Showing d:/Projects/Websites/Ruby On Rails/fact-it/app/views/devise/sessions/new.html.erb where line #11 raised:
uninitialized constant ActionView::CompiledTemplates::AppFormBuilder
8:
9: <p class="message error no-margin alert"><%= alert %></p>
10: <p class="notice"><%= notice %></p>
11: <%= form_for resource, :as => resource_name, :url => session_path(resource_name), :class => "form with-margin", :builder => AppFormBuilder do |f| %>
12: <p><%= f.label :email %><br />
13: <%= f.text_field :email %></p>
14:
答案 0 :(得分:3)
如果您想使用rails自动加载,则需要将此变量放在lib/app_form_builder.rb
中。
警告,在Rails 3中,此默认自动加载不再存在。您需要在application.rb
中添加此自动加载目录