Displaying 19 results from an estimated 19 matches for "type_cast".
2006 Mar 17
0
validates_format_of before type_cast?
Often I need to do a one-off validation before Rails has had a chance to
convert. For example, a date. Is there a general mechanism to cause
validations to run on the raw input or do I have to resort to:
private
def validate
unless attributes_before_type_cast[''date_of_loss''] =~
/^(\d+(-|\/)){2}\d{4}/
errors.add(''date_of_loss'', ''use the form: mm/dd/yyyy'')
end
end
Thanks
(BTW: I know there is a date validation plugin)
--
View this message in context: http://www.nabble.com/validates_format...
2008 Mar 19
2
ActiveRecord bug? ActiveRecord::ConnectionAdapters::Column.type_cast for float columns
Hi all,
I just noticed that in ActiveRecord::ConnectionAdapters::Column.type_cast[1]
(and type_cast_code[2]) the type casting for float columns simply does
value.to_f, whereas all the others have a rescue or call out to a method,
the default implementations of which have rescues or enough logic in that I
don''t think they''d fail.
Imagine the following:
create_...
2006 Feb 19
2
possible rails -> postgresql bug
Hi I have a problem accessing an array field in a Postgresql database.
Here is the table definition.
View "neil.flashing_codes"
Column | Type | Modifiers
-------------+-----------------------+-----------
code | character varying(10) |
description | text |
folds | integer[] |
View definition:
SELECT
2006 Jun 21
0
SQLServer Timestamp parsing problem in sqlserver_adapter.rb
...'parsedate''
from
c:/ruby/lib/ruby/1.8/gems/activerecord-1.14.2/lib/active_record_cnnection_adapters/sqlserver_adapter.rb:92:in
''cast_to_time''
from
c:/ruby/lib/ruby/1.8/gems/activerecord-1.14.2/lib/active_record_cnnection_adapters/sqlserver_adapter.rb:82:in
''type_cast''
...
I think the problem comes down to sqlserver_adapter.rb, in the type_cast
method, asking timestamps to cast_to_time instead of something that
SQLServer is expecting. My questions are two:
1) Does it look like I''ve traced this right?
2) Who knows how a timestamp record nee...
2007 Mar 29
1
ActiveRecord attributes -- strange behavior when adding Array to an element
Hi,
I have a database table and associated ActiveRecord model. I was
trying to store (temporarily) an array in one of the attribute
elements - not to save it, but just so that I can keep some form data
in a sensible place. A stripped down version of the problem I''m having
is:
p = Property.new(:bedroom_count => ["2","3"])
puts p.inspect # ==> will correctly show
2006 Feb 05
0
Enum patch for Rails
...activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
(revision 3486)
+++
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
(working copy)
@@ -18,7 +18,7 @@
@sql_type = sql_type
# have to do this one separately because type_cast depends on
#type
@default = type_cast(default)
- @limit = extract_limit(sql_type) unless sql_type.nil?
+ @limit = extract_limit_or_enum_values(sql_type) unless
sql_type.nil?
@primary = nil
@text = [:string, :text].include? @type
@number =...
2012 Nov 03
0
ids writer fields for HABTM relationship.
...M "people" WHERE
"people"."company_id" = 1 AND "people"."id" = ? LIMIT 1 [["id", "1"]]
(0.1ms) begin transaction
(0.0ms) rollback transaction
Completed 500 Internal Server Error in 2790ms
NoMethodError (undefined method `type_cast'' for nil:NilClass):
app/controllers/people_controller.rb:21:in `update''
[/code]
I scratched my head for quite a long time before finding out that after
restarting the rails server, the error would disappear and the Person
would actually be updated...
So with the help of pry an...
2007 Oct 07
0
Rails AR/Oracle Unit Test: [7769] failed (getting worse)
...b/active_record/connection_adapters/abstract/schema_definitions.rb:166:in `new_time''
./test/../lib/active_record/connection_adapters/abstract/schema_definitions.rb:116:in `string_to_time''
./test/../lib/active_record/connection_adapters/abstract/schema_definitions.rb:60:in `type_cast''
/usr/pkg/ruby184/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/oracle_adapter.rb:70:in `type_cast''
./test/../lib/active_record/connection_adapters/abstract/schema_definitions.rb:22:in `initialize''
/usr/pkg/ruby184/lib/ruby/g...
2006 Mar 03
0
binary_to_string/string_to_binary confusion
...naryTest) [binary_test.rb:36]:
Reloaded data differs from original.
<false> is not true.
It is failing because it is storing the raw X''<hex digits>'' data
instead of converting it back into binary.
Lookint at the code, it appears that database results pass through the
type_cast method to convert into native objects. That code shows that
:binary column types pass through binary_to_string. However, if I
implement binary_to_string to decode data fetched from the database,
then set accessors fail because for some reason they *also* call
binary_to_string when setting the val...
2006 Jan 17
2
How to run direct sql
How can i run and get the value from the following sql:
select avg(my_field) from my_table where which_year=''0506'' and
which_week <= 21 and my_foreign_key_id=10
cheers
--
Posted via http://www.ruby-forum.com/.
2005 Feb 19
0
[Error] Using validates_presence_of for datetime field causes parse error?
...e.rb:9:in `parsedate''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.6.0/lib/active_record/
connection_adapters/abstract_adapter.rb:228:in `string_to_time''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.6.0/lib/active_record/
connection_adapters/abstract_adapter.rb:196:in `type_cast''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.6.0/lib/active_record/
base.rb:1054:in `read_attribute''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.6.0/lib/active_record/
base.rb:1031:in `method_missing''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.6.0/lib...
2005 Dec 27
10
ActiveRecord flexible columns
I would like to have a table with flexible columns.
For example i have the following table customers:
id
name
email
The user should be able to save other columns to the database as well :
me = Customer.find(10)
me.name = ''me company''
me.email = ''me-RPlE4GnVVoJHoQZOM9yvow@public.gmane.org''
me.msn = ''me1234'' # custom columns
me.birthdate =
2007 Mar 30
1
write attribute coming from where?
...king for something more
transparent.
A before_filter is a partial solution, it would more or less work,
but with the current implementation if you do this
post.date = "22-jan-2007"
puts post.date
you get a nil instead of a Date object, because
ActiveRecord::Base::Column#type_cast is called by the getter via
read_attribute, who does not understand that string.
Another approach is to redefine the setter:
def date=(v)
v = my_date_parser(v) if v.is_a?(String)
write_attribute(:date, v)
end
but that breaks objet loading from the database because that setter...
2007 Apr 24
1
strange frozen string problem starting rails
...9;'
/home/mlc/src/democracynow.org/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:114:in
`string_to_time''
/home/mlc/src/democracynow.org/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:60:in
`type_cast''
/home/mlc/src/democracynow.org/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:22:in
`initialize''
/home/mlc/src/democracynow.org/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:93:in
`initialize'&...
2007 May 31
0
Rails AR/SQLServer Unit Test: [6912] failed (but getting better)
...out of range
./test/../lib/active_record/connection_adapters/sqlserver_adapter.rb:106:in `mktime''
./test/../lib/active_record/connection_adapters/sqlserver_adapter.rb:106:in `cast_to_datetime''
./test/../lib/active_record/connection_adapters/sqlserver_adapter.rb:79:in `type_cast''
./test/../lib/active_record/base.rb:2040:in `read_attribute''
./test/../lib/active_record/base.rb:2325:in `send''
./test/../lib/active_record/base.rb:2325:in `clone_attribute_value''
./test/../lib/active_record/base.rb:2319:in `clone_attributes'...
2005 Oct 17
8
Using active record for SELECT MAX(column) FROM ...
Hi,
Is there an easy way of querying an active record for a maximum column
value? I need to do queries like:
SELECT MAX(salary) FROM employees
TIA,
Jeroen
2005 Dec 27
3
myObject.send(column.name) from Agile Development book
I''m studying the Agile Development with Rails book. In the chapter that
first sets up the depot application (page 68), there is this bit of code
from a view:
<% for product in @products %>
<tr>
<% for column in Product.content_columns %>
<td><%=h product.send(column.name) %></td>
<% end %>
etc...
I am trying to absorb both Ruby and
2009 May 05
3
Oracle-JRuby error
...apter/jdbc_oracle.rb:63:in
`guess_date_or_time''
C:/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_oracle.rb:59:in
`string_to_time''
C:/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_oracle.rb:43:in
`type_cast''
C:/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:161:in
`field_changed?''
C:/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:135:in
`write_attribute_with_dirty''
C:/jruby-1.2.0/lib/ruby/gems/1.8/gems/activ...
2006 Jul 17
18
Inserting datetime value into SQL Server
I have a SQL Server column named StartTime of (SQL Server) type datetime
If I attempt to set the attribute using
public
def StartTime=(time)
write_attribute(:StartTime, "{ts ''1899-12-30
#{time.hour}:#{time.min}:#{time.sec}''}")
end
it''s inserting a NULL value.
Anyone else able to successfully insert a date time value into a SQL
Server table using