-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed regression - unable to use a range as choices for form.select. #4574
Conversation
@@ -4,6 +4,7 @@ module Tags | |||
class Select < Base #:nodoc: | |||
def initialize(object_name, method_name, template_object, choices, options, html_options) | |||
@choices = choices | |||
@choices = @choices.to_a if @choices.is_a?(Range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simply do @choices = choices.to_a
, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently @choices
can be a string, array or hash, so it breaks if we force it into an array. I'm happy to refactor the render method, which imho isn't particularly readable atm, but I think the original one-liner is a good interim solution for those relying ranges currently. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, so the current solution is fine for Rails 3.2, but on Rails master, I believe we can do @choices = choices.respond_to?(:to_a) ? choices.to_a : choices
. In any case, I am merging this, feel free to submit another patch for master that uses respond_to, thanks.
Fixed regression - unable to use a range as choices for form.select.
Could you please send a pull request for 3-2-stable as well? I have tried to backport but it got merge conflicts. Thanks! |
Thanks for sorting master. The 3-2-stable version is at #4604 |
I could have been cool to have |
Yeah, I actually considered that initially, but thought as a short fix it was better to not add a method to a core class. Saying that, if people like that idea I'll happily implement it instead...? |
Any thoughts on this, @josevalim? |
As of 3.2, form.select(:foobar, 1..3) fails with:
However, this still works fine with select_tag and options_for.
I've added tests for both cases and added a one-line fix to convert the range to an array for form.select.