RoR 3 - 覆盖 FormBuilder 默认的 f.submit 到按钮中
我有一个表单,为了布局(和将来的使用),我想知道如何更改生成的默认 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:
I have a form, and for layout (and future use), i would like to know how to change the default f.submit that generates a:
To a html tag that shouldn't give any errors.
What i have now is an extention on the formbuilder
In my view:
<%= form_for resource, :as => resource_name, :url => session_path(resource_name), :class => "form with-margin", :builder => AppFormBuilder do |f| %>
...
<%= f.submit %>
<% end %>
In my lib/appformbuilder:
class AppFormBuilder < ActionView::Helpers::FormBuilder
def submit(text, options = {})
options[:type] = "submit"
@template.content_tag(:button, text, options)
end
end
But this gives me an error:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用 Rails 自动加载,则需要将此变量放入
lib/app_form_builder.rb
中。警告,在 Rails 3 中,这种默认自动加载不再存在。您需要在 application.rb 中添加此自动加载目录
You need put this variable in
lib/app_form_builder.rb
if you want use the rails autoloading.Warning, in Rails 3 this default autoloading doesn't exist anymore. You need add this autoload directory in your application.rb