bignum too big to convert into `long' rails admin - ruby-on-rails

I am trying to search records in rails admin panel by entering a value of 569785067261691692240000 in the filter text field. I get a error "bignum too big to convert into `long'".
Search works fine if the text in the filter text field is alphanumeric but doesn't work if the text is numeric.
Can't understand what the problem is.
I am using 0.6.3 version of rails admin gem.

Your field might be defined as an integer/long field, which is limited to 2^32 or 2^64. Make it a string if you want to be able to enter such a long number.

Related

Generating values for dropdown ONLY for 'C' of CRUD

When choosing 'Add' in CRUD, how best to generate a list of choices to pick from a dropdown?
For U/update - just display what's there...
The field contents starts with a letter, followed by five numeric digits:{A-I,K-N,Z}#####
Each letter has a different 'max' value for the numeric part.
So when adding a new record, I'd like to offer a listbox with one of each letter and that letter's highest numeric value + 10.
So, if the max 'A' as A00120, and max 'B' B00030 (etc) the listbox would have A00130 and B00040.. etc
Save the user having to figure out which is 'next' when generating a new record.
? Thanks,
Mark
This time I'll not be able to come up with ready to use solution, but I must say - everything is possible with ATK4. You just have to customize and extend it to fit your needs :)
Speaking about your question above - I guess you have to split it in multiple parts.
First part is about how to show select box on Create and readonly or disabled field on Update. I guess you can make some custom Form field or pin some action to existing Form Field hook. Not sure exactly what's better in this case.
Second one is about data structure. I believe that this field actually should be 2 fields in DB and maybe (only maybe) merged together in ATK model with addExpression() just for user interface needs to display these 2 fields as one field easily in UI. Maybe such concatenated field will be useful also for searching, but definitely not as only one field stored in DB. Imagine how hard it'll be for DB engine to find max value if such field. Store it like type = letter, num = number and then search like SELECT max(num)+10 FROM t WHERE type='A'
Finally Third part is about how to generate this next number. I read your question 3 times and came to conclusion that actually you don't have to show this +10 numeric value in UI at all if it's hardly predefined anyway. Actually that'll not work correctly if this will be multi-user system which I guess it will. Instead just show simple select box with letters {A-I,K-N,Z} and calculate this next value exactly before inserting data in DB. That can be done using models insert hook. This will be much more appropriate solution and will be better for UI and also more stable because calculated in model not incorrectly in UI part.

Rails wont return decimals correctly

I'm using Rails 3.2.5 and when it return a value o :price for editing it just brings one decimal, eg. 600.0, i need that i bring 2 decimals (eg. 600.00) in database is recorded 600.00, in my locales i already set for 2 decimals, and still dont work.
I tried
number_to_currency(:price, :precision => 2)
but it works well for a view like "show", i need that it return the propper value for editing, on textfield.
in my migration the field "price" is set do decimal(15,2).
Can someone help?
Thank You!
The text fields are operating on the "native" value of the field, as it is handled by ActiveRecord, not as it is stored in the database.
Currency fields are tricky since ActiveRecord is translating between the database representation and the ruby/rails representation, a BigDecimal.
If your goal is that you want to show your users $1,000.00 and enable them to edit it, some ideas:
Use the Money gem Ylan S refers to.
Use an Edit in place widget Eg screencast. You'd use number_to_currency to display the value. When clicked, the input field would show the value without the currency symbol, commas for thousands separators, etc. Note that this is how Excel works: when you edit the value of a currency field, you don't enter 1,000. You enter 1000.
In my experience, instead of using decimal for storing currency, it's best to store the amounts in cents, as an integer. This will take care of multiple problems, including the one you are having now.
I have had much success in the past using the Money gem and its companion money-rails.
Issue solved using 'delocalize' gem.
Old but gold! :) Thank you all!
The simplest way to have your text_field display a formatted value is to pass it explicitly, like this:
f.text_field :price, :value => number_to_currency(:price, :precision => 2)
You'll need to interpret (and possibly re-format) the value in the controller method that handles the form.
See How can I format the value shown in a Rails edit field?

Rails Telephone field like a date field?

I using devise to allow users to register on my website. I have field for them to put in their telephone number when registering.
I however want to split the telephone field into 3 parts so you put in different parts of the number, kind of like a date.
Is it possible in rails to do something similar like you would with a date? When you have a date select on a form it gives the field names:
model[date(1i)]
model[date(2i)]
model[date(3i)]
Is this possible with other fields?
Cheers
I do not believe it is possible to cajole the date_select/select_date family into doing what you want.
You could try to mirror the DateTimeSelector class for your purposes: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/date_helper.rb
But why not just deal with this in the controller? You can slice and dice the input any way you want. If it's a one-time thing, I would do it that way. Otherwise, it might be worth your time to solve the problem in general, in which case you can make a gem for the world to use... although I think these 'i' suffixes are only useful for dates and times as far as ActiveRecord is concerned.

Comparing string before and after DB save in Rails?

I am trying to validate uniqueness on an article description. After I save it to the DB, if I retrieve it it comes back in a stripped down format (missing some chars). If I put a validator on the uniquness of the text in the desc. it doens't get called. If I do a find_by_desc it fails since the text is slightly different. Any ideas? I know the table is UTF-8, but really most of the characters are a few line endings and some dashes (-) here or there.
why you don't create an hash-code for that? create it before save, in validation check for the hash comparing. I don't suggest you to compare TEXT fields

How can I get Rails to interpret a text field as a datetime

My database has a datetime field, and I want to be able to create new entries. Obviously the Rails datetime_select helper isn't the most user friendly thing to have in your form.
I'd rather have a text field for the datetime (or one for the date, and one for the time) and interpret the inputs like PHP strtotime can.
I might just be searching the wrong keywords. Surely this has been discussed in great depth somewhere.
Thanks
:0)
Check out Railscast #32, I've used this method a few times and it works pretty well.

Resources