<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">141</assigned-user-id>
  <attachments-count type="integer">7</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2008-08-15T00:07:29+01:00</created-at>
  <creator-id type="integer">1741</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer">9903</milestone-id>
  <number type="integer">837</number>
  <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
  <priority type="integer">294</priority>
  <project-id type="integer">8994</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>committed</state>
  <tag>actionpack enhancement helper patch tested</tag>
  <title>disabled attribute and lambdas for option tags</title>
  <updated-at type="datetime">2009-02-28T15:27:39+00:00</updated-at>
  <user-id type="integer">1741</user-id>
  <user-name>Tekin</user-name>
  <creator-name>Tekin</creator-name>
  <assigned-user-name>Michael Koziarski</assigned-user-name>
  <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
  <milestone-title>2.x</milestone-title>
  <original-body>Adds the ability to specify the disabled attribute when generating option tags with the form helpers.</original-body>
  <latest-body>Adds the ability to specify the disabled attribute when generating option tags with the form helpers.</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;Adds the ability to specify the disabled attribute when generating option tags with the form helpers.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Adds the ability to specify the disabled attribute when generating option tags with the form helpers.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Adds the ability to specify the disabled attribute when generating option tags with the form helpers.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-15T00:07:29+01:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>PATCH: specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-08-15T00:07:29+01:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Here's an improved patch with added documentation.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Here's an improved patch with added documentation.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-16T11:38:52+01:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>PATCH: specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-08-16T11:38:52+01:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body></body>
      <body-html></body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-21T16:43:48+01:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- 
:title: &quot;PATCH: specify the disabled attribute for option tags&quot;
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-08-21T16:43:48+01:00</updated-at>
      <user-id type="integer">1366</user-id>
      <user-name>Pratik</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Up to date patch with support added to select and collection_select helpers.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Up to date patch with support added to select and
collection_select helpers.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-08T17:06:24+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-11-08T17:06:29+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Not sure if I like the hash with disabled values, but I don't have a better suggestion either.  Let's park this till post 2.2 and think a bit more about the API after that.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Not sure if I like the hash with disabled values, but I don't
have a better suggestion either. Let's park this till post 2.2 and
think a bit more about the API after that.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-10T20:05:40+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-11-10T20:05:43+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Thanks Michael.

Yeah, I'm not entirely happy with the API either but not sure what the  
alternative would be without drastic changes. In the mean time, I'll  
create a plugin and run it through it's paces.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Thanks Michael.&lt;/p&gt;
&lt;p&gt;Yeah, I'm not entirely happy with the API either but not sure
what the alternative would be without drastic changes. In the mean
time, I'll create a plugin and run it through it's paces.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-11-10T22:50:51+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-11-10T22:50:57+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I too have been wanting the ability to pass in disabled as an parameter for options_for_select.  However, I needed more control than the disabled = {} offered, since I have helper methods that generate the label/value pairs for options_for_select.  I needed the ability to have my helper method determine which options would be disabled, so that I wouldn't have to manually go in and specify various values as disabled (which could change and end up giving me more work to do).

So...  I modified the patch that was posted and tested it out, and it seems to work great for what I needed..  I thought I'd post it back in case anyone else finds it useful.

Thank you.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I too have been wanting the ability to pass in disabled as an
parameter for options_for_select. However, I needed more control
than the disabled = {} offered, since I have helper methods that
generate the label/value pairs for options_for_select. I needed the
ability to have my helper method determine which options would be
disabled, so that I wouldn't have to manually go in and specify
various values as disabled (which could change and end up giving me
more work to do).&lt;/p&gt;
&lt;p&gt;So... I modified the patch that was posted and tested it out,
and it seems to work great for what I needed.. I thought I'd post
it back in case anyone else finds it useful.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-28T12:27:17+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-12-28T12:27:20+00:00</updated-at>
      <user-id type="integer">41991</user-id>
      <user-name>patrick collins</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Glad you found it useful. I've also turned the patch into a plugin:

http://github.com/tekin/option_tags_will_disable/tree/master

The test coverage is patchy but it's working for my needs until something can get worked into core.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Glad you found it useful. I've also turned the patch into a
plugin:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/tekin/option_tags_will_disable/tree/master&quot;&gt;http://github.com/tekin/option_t...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The test coverage is patchy but it's working for my needs until
something can get worked into core.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-28T12:40:36+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-12-28T12:40:41+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>How about if instead of passing :disable =&gt; [1,2,3] you passed a proc which would return whether an item was disabled or not (so a bit closer in spirit to what options_from_collection_for_select does for id/value)

it might look a little like
@@@ ruby
f.select :foo_id, :foos, :disabled =&gt; lambda {|foo| some_condition(foo)}
@@@ 

Might be over the top but feels less cumbersome than having to explicitly write out those ids that are generated</body>
      <body-html>&lt;div&gt;&lt;p&gt;How about if instead of passing :disable =&amp;gt; [1,2,3] you
passed a proc which would return whether an item was disabled or
not (so a bit closer in spirit to what
options_from_collection_for_select does for id/value)&lt;/p&gt;
&lt;p&gt;it might look a little like&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
f.select :foo_id, :foos, :disabled =&amp;gt; lambda {|foo| some_condition(foo)}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Might be over the top but feels less cumbersome than having to
explicitly write out those ids that are generated&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-28T15:00:32+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-12-28T15:00:34+00:00</updated-at>
      <user-id type="integer">17477</user-id>
      <user-name>Frederick Cheung</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Well, I realized something still wasn't right with the behavior, and it got me to examine the original code for option_text_and_value.  It originally had this respond_to?(:first) and respont_to?(:last) --- which I don't quite understand what the relevance of that was, as that seems to return true in most all cases.

Anyway, I found that I was getting an error when passing in option, values without a disabled attribute, and it was because the option_text_and_value's passed in option param was a number 5..  Which I still don't get why that was happening.  Anyway, I changed things and tested it all out, and it works great (for me atleast)..  Like I said, this is ideal because you don't have to manually manage the disabled in the options_for_select, but rather you can have the disabled options be part of the array passed into it.

Here is the improved code:</body>
      <body-html>&lt;div&gt;&lt;p&gt;Well, I realized something still wasn't right with the behavior,
and it got me to examine the original code for
option_text_and_value. It originally had this respond_to?(:first)
and respont_to?(:last) --- which I don't quite understand what the
relevance of that was, as that seems to return true in most all
cases.&lt;/p&gt;
&lt;p&gt;Anyway, I found that I was getting an error when passing in
option, values without a disabled attribute, and it was because the
option_text_and_value's passed in option param was a number 5..
Which I still don't get why that was happening. Anyway, I changed
things and tested it all out, and it works great (for me atleast)..
Like I said, this is ideal because you don't have to manually
manage the disabled in the options_for_select, but rather you can
have the disabled options be part of the array passed into it.&lt;/p&gt;
&lt;p&gt;Here is the improved code:&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-28T22:30:07+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-12-28T22:30:09+00:00</updated-at>
      <user-id type="integer">41991</user-id>
      <user-name>patrick collins</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>@Frederick - That's not a bad idea! Will work something up and make it work for :selected too.

@Patrick - the :first/:last bit is necessary to support different types of container when calling options_for_select. see the &quot;rdoc&quot;:http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M001408</body>
      <body-html>&lt;div&gt;&lt;p&gt;@Frederick - That's not a bad idea! Will work something up and
make it work for :selected too.&lt;/p&gt;
&lt;p&gt;@Patrick - the :first/:last bit is necessary to support
different types of container when calling options_for_select. see
the &lt;a href=&quot;http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M001408&quot;&gt;
rdoc&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-30T20:04:45+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>Specify the disabled attribute for option tags</title>
      <updated-at type="datetime">2008-12-30T20:04:50+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>OK, here's an improved patch with more tests and the added bonus of being able to use a Proc to identify selected and disabled option tags.</body>
      <body-html>&lt;div&gt;&lt;p&gt;OK, here's an improved patch with more tests and the added bonus
of being able to use a Proc to identify selected and disabled
option tags.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-02T16:25:21+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- 
:title: Specify the disabled attribute for option tags
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-01-02T16:25:22+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>It looks very nice!! But maybe instead of having two parameters (selected and disabled), we could pass a hash.

Rails 2.2 (or it's 2.3?) changed quite some ActionView helpers to work with hashes instead of multiple arguments because the first is much more readable.

And another tip is to refactor this little piece of code into a private method:

@@@ ruby
  if selected.is_a?(Proc)
    selected_values = collection.map do |element|
      element.send(value_method) if selected.call(element) 
    end.compact
  else
    selected_values = selected
  end
@@@

You wrote it twice (for selected and disabled) and they exactly the 
same. =)</body>
      <body-html>&lt;div&gt;&lt;p&gt;It looks very nice!! But maybe instead of having two parameters
(selected and disabled), we could pass a hash.&lt;/p&gt;
&lt;p&gt;Rails 2.2 (or it's 2.3?) changed quite some ActionView helpers
to work with hashes instead of multiple arguments because the first
is much more readable.&lt;/p&gt;
&lt;p&gt;And another tip is to refactor this little piece of code into a
private method:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
  if selected.is_a?(Proc)
    selected_values = collection.map do |element|
      element.send(value_method) if selected.call(element) 
    end.compact
  else
    selected_values = selected
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You wrote it twice (for selected and disabled) and they exactly
the same. =)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-07T15:57:57+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-01-07T15:58:00+00:00</updated-at>
      <user-id type="integer">19965</user-id>
      <user-name>Jos&#233; Valim</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>Yeah, I'm ready to extract those two blocks of code but was waiting for some more feedback on the general principle first.

With regard to passing a hash instead of the extra parameter, do you mean repurpose the selected parameter so that it can be a selected value, an array of selected values, or a hash for both selected and disabled values?

I don't know if that feels right... Then again, it doesn't feel quite right adding the extra optional parameter to those methods either.

Anyone else think this would be a better approach?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Yeah, I'm ready to extract those two blocks of code but was
waiting for some more feedback on the general principle first.&lt;/p&gt;
&lt;p&gt;With regard to passing a hash instead of the extra parameter, do
you mean repurpose the selected parameter so that it can be a
selected value, an array of selected values, or a hash for both
selected and disabled values?&lt;/p&gt;
&lt;p&gt;I don't know if that feels right... Then again, it doesn't feel
quite right adding the extra optional parameter to those methods
either.&lt;/p&gt;
&lt;p&gt;Anyone else think this would be a better approach?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-07T21:42:19+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-01-07T21:42:21+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>OK, I've reworked this patch, rebasing with edge and removing some of the duplication. 

I've also worked up an alternative which doesn't change the API and instead duck-types the selected parameter so that you can pass in a hash if you want to specify disabled option tags.

Personally, I'm not convinced by the duck-typing, but it does have the advantage of not adding any more parameters (optional or otherwise) to the methods.</body>
      <body-html>&lt;div&gt;&lt;p&gt;OK, I've reworked this patch, rebasing with edge and removing
some of the duplication.&lt;/p&gt;
&lt;p&gt;I've also worked up an alternative which doesn't change the API
and instead duck-types the selected parameter so that you can pass
in a hash if you want to specify disabled option tags.&lt;/p&gt;
&lt;p&gt;Personally, I'm not convinced by the duck-typing, but it does
have the advantage of not adding any more parameters (optional or
otherwise) to the methods.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-29T11:54:49+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-01-29T11:54:51+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">3</attachments-count>
      <body>Here's the second duck-typing method patch. 

Would be good to get this into 2.3, any suggestions on moving forward with this?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Here's the second duck-typing method patch.&lt;/p&gt;
&lt;p&gt;Would be good to get this into 2.3, any suggestions on moving
forward with this?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-01-29T11:56:06+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-01-29T11:56:11+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>I like the look of this, but we'll need changes to the documentation too so people know how to use it :)</body>
      <body-html>&lt;div&gt;&lt;p&gt;I like the look of this, but we'll need changes to the
documentation too so people know how to use it :)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-02-01T01:54:36+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- 
:assigned_user: 
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-01T01:54:41+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">4</attachments-count>
      <body>OK, here's an updated patch with some no-frills documentation. Hopefully someone with better writing skills and docrails access will spruce them up!</body>
      <body-html>&lt;div&gt;&lt;p&gt;OK, here's an updated patch with some no-frills documentation.
Hopefully someone with better writing skills and docrails access
will spruce them up!&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-02-01T12:49:09+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-01T12:49:13+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">5</attachments-count>
      <body>With 2.3 RC1 out, is this going to slip to the next release? Otherwise, let me know if there is anything else needed from my end to get this patch into core before 2.3 goes official.</body>
      <body-html>&lt;div&gt;&lt;p&gt;With 2.3 RC1 out, is this going to slip to the next release?
Otherwise, let me know if there is anything else needed from my end
to get this patch into core before 2.3 goes official.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-02-09T14:36:19+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-09T14:36:20+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">5</attachments-count>
      <body>Tekin,

Sorry for the delay, this one fell of my radar.  It doesn't apply
cleanly at present, but if you can rebase it it looks good to me.

Also, perhaps split the dummy_posts change into another changeset, took
me a while to separate out the changes in the patch from the (nice)
refactoring.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Tekin,&lt;/p&gt;
&lt;p&gt;Sorry for the delay, this one fell of my radar. It doesn't apply
cleanly at present, but if you can rebase it it looks good to
me.&lt;/p&gt;
&lt;p&gt;Also, perhaps split the dummy_posts change into another
changeset, took me a while to separate out the changes in the patch
from the (nice) refactoring.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-02-13T09:25:51+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-13T09:25:52+00:00</updated-at>
      <user-id type="integer">141</user-id>
      <user-name>Michael Koziarski</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">5</attachments-count>
      <body>OK, new patch, rebased with edge, with separate commits to make things clearer. Much nicer!</body>
      <body-html>&lt;div&gt;&lt;p&gt;OK, new patch, rebased with edge, with separate commits to make
things clearer. Much nicer!&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-02-14T01:02:48+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-14T01:02:53+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">6</attachments-count>
      <body>(from [d676a7f18a5df86096f708052eb0c62ce4063310]) Updated rdoc to reflect changes to form option helpers

Signed-off-by: Michael Koziarski &lt;michael@koziarski.com&gt;
[#837 state:committed]
http://github.com/rails/rails/commit/d676a7f18a5df86096f708052eb0c62ce4063310</body>
      <body-html>&lt;div&gt;&lt;p&gt;(from [d676a7f18a5df86096f708052eb0c62ce4063310]) Updated rdoc
to reflect changes to form option helpers&lt;/p&gt;
&lt;p&gt;Signed-off-by: Michael Koziarski &lt;a href=&quot;mailto:michael@koziarski.com&quot;&gt;michael@koziarski.com&lt;/a&gt; [&lt;a href=&quot;/projects/8994/tickets/837&quot; title=&quot;Ticket #837&quot;&gt;#837&lt;/a&gt;
state:committed] &lt;a href=&quot;http://github.com/rails/rails/commit/d676a7f18a5df86096f708052eb0c62ce4063310&quot;&gt;
http://github.com/rails/rails/co...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-02-14T01:57:10+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-14T01:57:12+00:00</updated-at>
      <user-id type="integer">17393</user-id>
      <user-name>Repository</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">141</assigned-user-id>
      <attachments-count type="integer">6</attachments-count>
      <body>Here's a patch for the changelog so it's not overlooked.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Here's a patch for the changelog so it's not overlooked.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-02-28T15:27:35+00:00</created-at>
      <creator-id type="integer">1741</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">837</number>
      <permalink>patch-specify-the-disabled-attribute-for-option-tags</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>committed</state>
      <tag>actionpack enhancement helper patch tested</tag>
      <title>disabled attribute and lambdas for option tags</title>
      <updated-at type="datetime">2009-02-28T15:27:39+00:00</updated-at>
      <user-id type="integer">1741</user-id>
      <user-name>Tekin</user-name>
      <creator-name>Tekin</creator-name>
      <assigned-user-name>Michael Koziarski</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/837</url>
      <milestone-title>2.x</milestone-title>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>2e88c7f25147a9c97492e40d415d2be016a163ee</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2008-12-28T12:27:17+00:00</created-at>
      <filename>options_for_select_change.txt</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">74107</id>
      <size type="integer">1701</size>
      <uploader-id type="integer">41991</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/74107/options_for_select_change.txt</url>
    </attachment>
    <attachment type="Attachment">
      <code>160bee931122ab5a1a075e92f47c0117d3f85360</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2008-12-28T22:30:08+00:00</created-at>
      <filename>options_for_select_change.txt</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">74130</id>
      <size type="integer">1098</size>
      <uploader-id type="integer">41991</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/74130/options_for_select_change.txt</url>
    </attachment>
    <attachment type="Attachment">
      <code>55fc070cf8cba9166fa60b2660f61fed2e6e9656</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-01-29T11:54:49+00:00</created-at>
      <filename>enhance-option-tag-helpers-to-allow-disabled-with-extra-param.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">82835</id>
      <size type="integer">21289</size>
      <uploader-id type="integer">1741</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/82835/enhance-option-tag-helpers-to-allow-disabled-with-extra-param.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>117b685445704f5e2a06ccaf9a05c1f305d3a732</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-01-29T11:56:06+00:00</created-at>
      <filename>enhance-option-tag-helpers-to-allow-disabled-with-duck-typing.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">82836</id>
      <size type="integer">20015</size>
      <uploader-id type="integer">1741</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/82836/enhance-option-tag-helpers-to-allow-disabled-with-duck-typing.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>a8fa827148ff233c560e684556e25f7b32f46a12</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-02-01T12:49:09+00:00</created-at>
      <filename>enhance-option-tag-helpers-to-allow-disabled-with-duck-typing.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">83660</id>
      <size type="integer">28415</size>
      <uploader-id type="integer">1741</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/83660/enhance-option-tag-helpers-to-allow-disabled-with-duck-typing.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>b01bfd9d620a07503dfbd0881488daaae994f377</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-02-14T01:02:48+00:00</created-at>
      <filename>enhance-option-tag-helpers.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">88826</id>
      <size type="integer">30017</size>
      <uploader-id type="integer">1741</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/88826/enhance-option-tag-helpers.diff</url>
    </attachment>
    <attachment type="Attachment">
      <code>a42a0c82fc1d65974e87e59f59a765bdd0c4585d</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-02-28T15:27:35+00:00</created-at>
      <filename>changelog-update.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">94290</id>
      <size type="integer">936</size>
      <uploader-id type="integer">1741</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/94290/changelog-update.diff</url>
    </attachment>
  </attachments>
</ticket>
