Changeset 1171
- Timestamp:
- 01/05/08 12:41:40 (9 months ago)
- Files:
-
- plugins/merb_helpers/lib/merb_helpers/form_helpers.rb (modified) (3 diffs)
- plugins/merb_helpers/spec/merb_helpers_spec.rb (modified) (1 diff)
- plugins/merb_helpers/spec/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/merb_helpers/lib/merb_helpers/form_helpers.rb
r1169 r1171 49 49 # <%= error_messages_for :person %> 50 50 def error_messages_for(obj, error_li = nil, html_class='submittal_failed') 51 return "" if obj.errors.empty?51 return "" if !obj.respond_to?(:errors) || obj.errors.empty? 52 52 header_message = block_given? ? yield(obj.errors) : "<h2>Form submittal failed because of #{obj.errors.size} #{obj.errors.size == 1 ? 'problem' : 'problems'}</h2>" 53 53 ret = %Q{ … … 552 552 # Fall silently back to post if a method is given that is not supported here 553 553 def set_form_method(options = {}, obj = nil) 554 options[:method] ||= (!obj || obj.new_record? ? :post : :put)554 options[:method] ||= (!obj || (obj.respond_to?(:new_record?) && !obj.new_record?) ? :put : :post) 555 555 if ![:get,:post].include?(options[:method]) 556 556 fake_form_method = options[:method] if [:put, :delete].include?(options[:method]) … … 576 576 577 577 def errorify_field(attrs, col) 578 attrs.add_html_class!("error") if @_obj. errors.on(col)578 attrs.add_html_class!("error") if @_obj.respond_to?(:errors) && @_obj.errors.on(col) 579 579 end 580 580 plugins/merb_helpers/spec/merb_helpers_spec.rb
r1169 r1171 109 109 @obj2 = FakeModel2.new 110 110 form_for(:obj2) do 111 end 112 _buffer.should match_tag(:form, :method => "post") 113 _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method") 114 end 115 116 it "should set the method to post if the object does not respond to new_record?" do 117 @obj3 = FakeModel3.new 118 form_for(:obj3) do 111 119 end 112 120 _buffer.should match_tag(:form, :method => "post") plugins/merb_helpers/spec/spec_helper.rb
r1146 r1171 82 82 end 83 83 84 class FakeModel3 85 attr_accessor :foo, :bar 86 end 87 88 84 89 class FakeErrors 85 90
