Skip to content
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

Allow to pass block to select helper in Rails >= 4.1.0 #229

Merged
merged 1 commit into from
Jan 19, 2016

Conversation

doits
Copy link
Contributor

@doits doits commented Jun 18, 2015

Beginning with Rails 4.1.0, the select method allows to pass a block to
render as the options string:

http://apidock.com/rails/v4.1.8/ActionView/Helpers/FormOptionsHelper/select
(the link points to 4.1.8, but it is the same for 4.1.0)

Adapt the gem to allow this.

The test is marked to run on Rails >= 4.1.0 only.

One problem remains though: When updating Rails to 4.1.0 in test
environment, many other tests fail because the order of attributes in
the output changed. I don't know how to solve this yet without rewriting
the expected output for different Rails versions (wich is a cumbersome
task ...).

Beginning with Rails 4.1.0, the select method allows to pass a block to
render as the options string:

http://apidock.com/rails/v4.1.8/ActionView/Helpers/FormOptionsHelper/select
(the link points to 4.1.8, but it is the same for 4.1.0)

Adapt the gem to allow this.

The test is marked to run on Rails >= 4.1.0 only.

One problem remains though: When updating Rails to 4.1.0 in test
environment, many other tests fail because the order of attributes in
the output changed. I don't know how to solve this yet without rewriting
the expected output for different Rails versions (wich is a cumbersome
task ...).
@mattbrictson
Copy link
Contributor

👍

I would also appreciate a the ability to use a block with select. For now I am monkey patching bootstrap_form in a similar fashion to this PR.

This feature is really useful if you want to generate custom choices for the select element, with e.g. custom data attributes to each choice.

@lancedikson
Copy link

👍

@lancedikson
Copy link

@manuelmeurer, check this please

@manuelmeurer
Copy link
Member

@lancedikson I'm not actively involved in development of this project.

/cc @potenza

@lancedikson
Copy link

@manuelmeurer, looks like @potenza is not active on GH at this time 😞

@manuelmeurer
Copy link
Member

@baldwindavid @carloslopes @sethvargo @wingrunr21 Can one of you guys have a look?

@wingrunr21
Copy link
Contributor

I'm also not actively involved but I don't really see anything wrong with the PR.

@doits
Copy link
Contributor Author

doits commented Jan 10, 2016

I'm using this for the last months and have no problems with it. Feel free to use the fork.

Only problem with this PR is that updating to Rails >= 4.1.0 in test environment makes all other tests fail, because the output order of attributes has changed and the tests depend on this. One would have to rewrite all tests to not depend on ordering, e.g. not comparing output strings exactly but either checking for attributes (string.include?("...")) or parsing the output (nokogiri).

Will there be a rewrite for bootstrap 4? Maybe tests will be rewritten in then, too, then this should be taken in consideration to make tests more stable.

@carloslopes
Copy link
Member

Hey guys! Sorry about the delay!

The code appears to be fine for me, but I'm a little bit concerned about what you said of the Rails 4.1.0 issue.

The other examples fail when we use 4.1.0 on test environment?

@doits
Copy link
Contributor Author

doits commented Jan 15, 2016

The other examples fail when we use 4.1.0 on test environment?

Exactly!

@carloslopes
Copy link
Member

So, the lib breaks if someone uses rails 4.1.0?

@doits
Copy link
Contributor Author

doits commented Jan 19, 2016

No, just the tests fail due to the way they are written.

Example: The tests check that output is exact, for example:

<input class="foo" name="blah">

Rails < 4.1 generates this exactly, but Rails >= 4.1 generates:

<input name="blah" class="foo">

Only order of attributes changed, but everything is still fine. But test fails of course. Hope you get the point.

@carloslopes
Copy link
Member

Yep, I'm not currently using the gem anymore. But like different people said that this is fine, I'll merge it

carloslopes added a commit that referenced this pull request Jan 19, 2016
Allow to pass block to select helper in Rails >= 4.1.0
@carloslopes carloslopes merged commit 941edb9 into bootstrap-ruby:master Jan 19, 2016
@carloslopes
Copy link
Member

There's something more you need to be merged? Then I can close a new version

@mattbrictson
Copy link
Contributor

Hi @doits, thanks again for this PR. You mentioned how the tests fail with Rails 4.1. Do you have any suggestions for how we can fix it? I opened a new issue to discuss it here: #273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants