Comments (17)
Can you please provide the code for enum definition, model enumeration (if enum
not defined in the model), and the view select code.
On 26/09/12 2:52 PM, Kurakin Alexander wrote:
It seems |select|'s |checked| value isn't set currently. Yeah, Rails checks
|model.color| and gets |red| but not |1|. But db's values is |1| instead. Oops,
checked value is wrong, that why current value of select box is blank, amn't I
right?—
Reply to this email directly or view it on GitHub
#17.
from active_enum.
Do you have
require 'active_enum/form_helpers/formtastic2'
in the initializer?
from active_enum.
If so, please try and add a failing spec here
https://github.com/adzap/active_enum/blob/master/spec/active_enum/form_helpers/formtastic2_spec.rb
from active_enum.
@adzap Yes, I have. I'll try.
from active_enum.
@adzap sorry, formtastic isn't important here. Test fails with all forms.
from active_enum.
@kuraga the problem is you are assigning a string value to sex attribute. You must assign a symbol value for the gem to intercept and convert it to the enum integer value.
from active_enum.
@kuraga a shortcut to get the enum class for an attribute is
record.sex(:enum)
from active_enum.
@adzap Yes, you're right, 05bd57f. But real forms don't work right. I've created an app to demonstrate, visit /people
please, edit sex
and edit one more time please. https://github.com/kuraga/app_for_active_enum_issue_17
from active_enum.
I see the problem. You have the use_name_as_value config option set. This means if you use the field in a form select it is trying to match 'Male' to 1 in the select options. Play with it in the console and you can see what @person.sex will return a string value. You can't use the to_select form on the enum options in the select if you have this option set.
Why did want to use this option? Was just to display in the show action?
from active_enum.
@adzap I know all of that. I wrote this explanation in previous issue #16. In this issue I just wanted to formalize it (and verify by together). Yes, just to display in show action without some specific parameters
I just think it's an issue to think about in next versions. Because maybe it's a strange behavior (form without selected value by default). Ok, what about to change behavior for formtastic
and simple_form
situation, at least? I just propose to think about it later.
And your gem is very good to contribute for me because my experience isn't too long :-). But my ideas are strange, may be... Thanks very much.
from active_enum.
Well, didn't actually. The vital fact of the use_name_as_value config setting was never mentioned. There is no problem with the gem as I see it, only the possible addition of a warning.
What change to formastic or simple_firm do you mean?
On 01/10/2012, at 6:15 PM, Kurakin Alexander [email protected] wrote:
@adzap I know all of that. I wrote this explanation in previous issue #16. In this issue I just wanted to formalize it (and verify by together). Yes, just to display in show action without some specific parameters
I just think it's an issue to think about in next versions. Because it's a strange behavior. Ok, about what about to change behavior for formtastic and simple_form situation, at least? I just propose to think about it later.
And your gem is very good to contribute for me because my experience isn't too long :-). But my ideas are strange, may be... Thanks very much.
—
Reply to this email directly or view it on GitHub.
from active_enum.
Yes, I wasn't right. I should use String
id
instead of Fixnum
... Sorry.
from active_enum.
Ok, let's begin again :)
There is a form. It seems select's checked value isn't set currently. Yeah, Rails checks model.color
and gets red
but not 1
. But db's values is 1
instead. Oops, checked value is wrong, that why current value of select box is blank, amn't I right?
But if we set id==value
(i.e. red
), it's all good here. red
value is checked. I can modify test that I've wrote above to show it... Thanks.
P.S. The problem is we can't use String
s, see #21. If we set id==value==1
, problems with i18n
will be...
from active_enum.
This is not the problem. You are confusing the use_name_as_value concept, and the use case for having string ids at all. Turn off use_name_as_value and use model.color(:name) where you need it.
from active_enum.
@adzap You're right. But if use_name_as_value==false
then model.color
isn't translated. Just there are two situations the are not possible simultaneously (yes?): 1) puts model.color
is translated; 2) in form, select
's checked value is right.
from active_enum.
puts model.color(:name) is what you want.
selects will work as normal with use_name_as_value = false. You can't get both an id and translated name from model.color, end of story.
from active_enum.
@adzap foooh. Yahoo! Yes. That's a "problem" that I'm explaining :) I think that's good to think if you will change behavior. Because if I start use active_enum
I should rewrite views (model.color
to model.color(:name)
...
from active_enum.
Related Issues (20)
- Using ids instead of names to store HOT 2
- Attribute isn't translated if id isn't a Fixnum HOT 1
- Enum IDs Can't Be Strings HOT 6
- plans to provide helpers for javascript or client_side_validations HOT 6
- Provide rspec matcher out of the box HOT 1
- ActionView::Template::Error (Unable to find input class for enum) HOT 1
- Boolean check does not work with with option `config.use_name_as_value = true`
- to_select method to return list based on specific enums HOT 1
- Rails 4 compatibility HOT 2
- Reopen issue #21 (string id's)? HOT 2
- Missing note on i18n configuration in project readme HOT 2
- Rails 4 support not available in RubyGems HOT 8
- Access Enum as Constant HOT 1
- Add functionality to get id and name of enum by a method
- Retrieving the key as well as the `id` and `name` HOT 2
- Add enumerate method fails on Rails 6.1 HOT 1
- Formtastic Support HOT 2
- Generate boolean method like ActiveRecord::Enum
- String keys in database HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from active_enum.