Skip to content

Instantly share code, notes, and snippets.

@adelcambre
Created February 19, 2009 00:05
Show Gist options
  • Save adelcambre/66624 to your computer and use it in GitHub Desktop.
Save adelcambre/66624 to your computer and use it in GitHub Desktop.
commit 31753b203b5a6807a3b33640ae9d056b330c757c
Author: Andy Delcambre <adelcambre@engineyard.com>
Date: Wed Feb 18 16:04:56 2009 -0800
fix for bound select helper
diff --git a/merb-helpers/lib/merb-helpers/form/builder.rb b/merb-helpers/lib/merb-helpers/form/builder.rb
index 7485b1f..5db93d4 100644
--- a/merb-helpers/lib/merb-helpers/form/builder.rb
+++ b/merb-helpers/lib/merb-helpers/form/builder.rb
@@ -162,9 +162,8 @@ module Merb::Helpers::Form::Builder
end
def update_bound_select(method, attrs)
- attrs[:value_method] ||= method
attrs[:text_method] ||= attrs[:value_method] || :to_s
- attrs[:selected] ||= control_value(attrs[:value_method])
+ attrs[:selected] ||= control_value(method)
end
def update_unbound_controls(attrs, type)
diff --git a/merb-helpers/spec/fixture/app/models/second_generic_fake_model.rb b/merb-helpers/spec/fixture/app/models/second_generic_fake_model.rb
index 29125e3..94ae30e 100644
--- a/merb-helpers/spec/fixture/app/models/second_generic_fake_model.rb
+++ b/merb-helpers/spec/fixture/app/models/second_generic_fake_model.rb
@@ -1,4 +1,5 @@
class FakeModel2 < FakeModel
+ attr_accessor :car_model
def id
1
end
diff --git a/merb-helpers/spec/fixture/app/views/bound_option_tag_specs/grouped.html.erb b/merb-helpers/spec/fixture/app/views/bound_option_tag_specs/grouped.html.erb
index fb21515..1ea68a4 100644
--- a/merb-helpers/spec/fixture/app/views/bound_option_tag_specs/grouped.html.erb
+++ b/merb-helpers/spec/fixture/app/views/bound_option_tag_specs/grouped.html.erb
@@ -1,3 +1,3 @@
-<%= form_for @model1 do %>
- <%= select(:vin, :text_method => "model", :collection => @collection) %>
+<%= form_for @model4 do %>
+ <%= select(:car_model, :text_method => "model", :value_method => "vin", :collection => @collection) %>
<% end =%>
diff --git a/merb-helpers/spec/merb_helpers_form_spec.rb b/merb-helpers/spec/merb_helpers_form_spec.rb
index c32c499..906d2b5 100644
--- a/merb-helpers/spec/merb_helpers_form_spec.rb
+++ b/merb-helpers/spec/merb_helpers_form_spec.rb
@@ -1013,9 +1013,11 @@ describe "bound option tags" do
model1 = FakeModel.new ; model1.make = "Ford" ; model1.model = "Mustang" ; model1.vin = '1'
model2 = FakeModel.new ; model2.make = "Ford" ; model2.model = "Falcon" ; model2.vin = '2'
model3 = FakeModel.new ; model3.make = "Holden" ; model3.model = "Commodore" ; model3.vin = '3'
+ model4 = FakeModel2.new; model4.car_model = '1'
@c.instance_variable_set(:@model1, model1)
@c.instance_variable_set(:@model2, model2)
@c.instance_variable_set(:@model3, model3)
+ @c.instance_variable_set(:@model4, model4)
@c.instance_variable_set(:@collection, [model1, model2, model3].inject({}) {|s,e| (s[e.make] ||= []) << e; s })
r = @c.render :grouped
# Blank actually defaults to ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment