This happened when updating text area.
If you have a valid EF model with the correct field length, this shouldn't be a problem (for example, by decorating with Length attributes)
This type of error generally occurs when you try to put characters or values more than what you have specified in your table schema.
Like in that case: you specify varchar(10), but you are trying to store a value that contains 19 characters.
Solution:
Check your parameter sizes against column sizes and the field(s)
Try updating each property one by one with a .SaveChanges() to find out which one is causing the error.
i am learning rails and working on a project in which i need to convert string column type to binary
i tried
change_column :workers, :sin,:binary
But i am not able to do so as i am getting.
PG::DatatypeMismatch: ERROR: column "sin" cannot be cast automatically to type bytea
i want that my sin data should be stored in encrypted form and i am using this gem
https://github.com/stas/active_record-pgcrypto
i also want to decrypt the data while showing in the UI.
I am open for suggestions please.
Thank you
I think the easiest approach is to do a data migration. Create a new binary column, then for each record transform your current column to the encrypted form with ActiveRecord::PGCrypto::SymmetricCoder.encrypt(value) and store this encrypted value in the new binary column. Note I haven't tested it, I just checked the code of the gem.
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.
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?
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