I want to override the ‘tag’ method in
ActionView::Helpers::TagHelper to do some generalized
error handling similar to the way scaffolding puts a
red border around fields that fail validation.
I’ve created a file lib/rails_patches/tag_helper.rb
which contains the following.
module ActionView
module Helpers
module TagHelper
alias_method :orig_tag, :tag
def tag(name, options = nil, open = false)
breakpoint
orig_tag(name, options, open)
end
end
end
end
I then have a view with the following
New post
<%= start_form_tag :action => 'create' %>Title
<%= text_field 'post', 'title' %>
<%= submit_tag “Create” %>
<%= end_form_tag %>
Now here is my problem. Each of these tag helpers
calls the tag method to created it’s tag. However,
only some of them use my custom tag method. Here’s the
output. Notice that text_field does not use my
customer tag method. Why is that?
Executing break point at
/Users/jay/demo/public/…/config/…/lib/rails_patches/tag_helper.rb:6
in `tag’
irb(#<#Class:0x2578980:0x2578958>):001:0> name
=> :form
irb(#<#Class:0x2578980:0x2578958>):002:0> options
=> {“action”=>“/post/create”, “method”=>“post”}
irb(#<#Class:0x2578980:0x2578958>):003:0> exit
Executing break point at
/Users/jay/demo/public/…/config/…/lib/rails_patches/tag_helper.rb:6
in `tag’
irb(#<#Class:0x2578980:0x2578958>):001:0> name
=> :input
irb(#<#Class:0x2578980:0x2578958>):002:0> options
=> {“name”=>“commit”, “type”=>“submit”,
“value”=>“Create”}
irb(#<#Class:0x2578980:0x2578958>):003:0> exit
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around