search for: _before_type_cast

Displaying 17 results from an estimated 17 matches for "_before_type_cast".

2008 Jul 30
0
timezone support breaks _before_type_cast method
Some code in my current project validates date time format using _before_type_cast method. But after adding "config.time_zone = "UTC" in environment.rb, we can''t get string raw values of some date time columns using _before_type_cast. for example, >> p = Person.new(:name => ''sean'', :birthday => ''1989-01-23'')...
2006 Aug 19
5
Form helpers don''t work with facade columns?
Hello all, I''ve been trying to use a facade column but I notice that the form helpers don''t seem to respect the facade. In the following example I''m trying to story the prices as Integer values but present them to the user as decimals. class Product < ActiveRecord::Base def price=(new_price) write_attribute(:price, Float(new_price)*100) end def price
2006 May 18
3
populating array of text_fields from an array of model objects
I have in my view the following: <% 0.upto(@num_performances) do |idx| -%> <%= text_field ''performance'', ''city'', :index => idx, %> <%= text_field ''performance'', ''venue'', :index => idx, %> <% end -%> and in my controller I have: @performance = [Performance.new("city" =>
2006 Aug 14
1
What fields_for really for?
...In edit.rhtml for SuburbController I need to specify region_id. There is no region_id in suburb model so first I added these lines to it: ... class Suburb < ActiveRecord::Base belongs_to :district attr_writer :region_id def region_id district.region_id if district end def region_id_before_type_cast region_id end validates_numericality_of :region_id, :only_integer => true end ... Its all working now but it looks messy! And I need this functionality in another few places. Obviously I dont want to put this rubbish into other models! I recently come across fields_for helper. So I c...
2006 Mar 01
3
Form helpers and overloaded methods - help!
Can someone explain why form helpers appear to bypass any model methods I override for fields that are bound to database fields? It would be great if someone could tell me how to force the form field, etc to call the method instead of looking at the database / attributes collection. Let''s say I have a column called ''price'' in my database table "books"
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and automatically populate, but it shouldn''t be based on AR. In fact I often have a bunch of small forms that I can''t really justify writing a whole new model class for anyway. I''d like to validate the form input, and then use rails helpers to automatically populate the form if validations fail.
2006 Jul 11
1
Validating composed_of
...class. I want to make sure that the price only contains a price to 2 decimal places i.e. 1.25. This is because if someone enters 1.256 then the price ends being 1.26. The standard validations that I''ve tried don''t work. validates_numericality_of complains of a lack of "price_before_type_cast". How do you validate these attributes? Many thanks, Jordan
2006 Jun 25
0
Using the database schema to help validate data
...text columns + if column.text? then + # varchars have a limit, while text columns generally do not + if column.limit then + # this is a hack for attributes which are reserved words like ''type'' + name = "#{column.name}_before_type_cast" + validates_length_of name, :maximum=>column.limit + end + end + } + end + def condition_block?(condition) condition.respond_to?("call") && (condition.arity == 1 || condition.arity == -1) end -- Posted...
2006 Apr 08
1
text_field behaviour with validations
Hi, The text_field method sets the class of the field to "invalid" when the object you specified is invalid (when using validations). This is to facilitate working with validations. Is there anything else it does? In a certain non-standard situation I''m forced to use text_field_tag, instead of text_field. This means I have to take care of the validations myself as well.
2006 Mar 11
1
unit testing date columns
...llowing along the tute in Agile Web Dev with rails book. I have a table with a created_at timestamp column in mysql. My test always fails when testing the result of the created_at column. The book says my test should look like: assert_equal "2006-03-09 21:01:37", @thing.date_available_before_type_cast but when I run my test I get 1 error returned: "undefined method date_available_before_type_cast" what am I doing wrong? -- Posted via http://www.ruby-forum.com/.
2006 Feb 15
2
First unit test fails
I''ve just started working through ''Agile'' chapter 12 ''Testing''. I''ve followed the steps carefully, setting up a fixture and unit test to check the creation of an order. When I run the test I get the following: Loaded suite test/unit/order_test Started F Finished in 0.108008 seconds. 1) Failure: test_create(OrderTest)
2006 Feb 28
0
ActiveRecord: Legacy primary keys
...self.id = params[self.class.primary_key] if params && params.has_key?(self.class.primary_key) end EOS end def self.set_primary_key pk super alias_method pk, :id alias_method pk + ''='', :id= self.class_eval <<-EOS def #{pk}_before_type_cast return read_attribute(self.class.primary_key) if read_attribute(self.class.primary_key) return self.id end EOS end def self.content_columns @content_columns = columns.reject { |c| c.name =~ /(_id|_count)$/ || c.name == inheritance_column } end def update...
2006 Jan 06
0
How to save new record into DB after set_primary_kay and remove id?
Hi, I''m new in ruby and rails. I tried to set_primary_kay and remove id from a table, but can not save new records into db because of the validation and the _before_type_cast . Tried to find help on the web but did not get it. Pleas help. Thanks lot. Vince
2008 Jul 02
0
before_type_case broken?
Hey, I''ve noticed that I seem unable to get a _before_type_cast value for dates in 2.1. Specifically, if I assign a date string to a date attribute, and then call attribute_before_type_cast I get a TimeWithZone instead of a String: model.start_date = "2001/01/02" model.start_date.class = ActiveSupport::TimeWithZone model.start_date_before_type_cast.c...
2007 May 01
2
Problem validating boolean
Hi I''ve got a problem validating a boolean and I can''t see what the problem is. Here''s my model: class FinanceAgreement < ActiveRecord::Base belongs_to :asset validates_presence_of :finance_company validates_inclusion_of :balance, :in => 0.01..10_000_000 validates_inclusion_of :term, :in => 1..600 validates_numericality_of
2007 Oct 24
13
Ryan Bates' Multi-object Forms and the date_select
I think I''ve found a bug with Edge. I''m trying out Ryan Bates'' multi-object form technique shown in one of his Rails-casts (railscasts.com/episodes/75). If you use a fields_for similar to that shown (here: http://pastie.caboo.se/110480), you get a Server Error 500: ------ Status: 500 Internal Server Error Conflicting types for parameter containers. Expected an
2006 Jan 05
13
Date Validation
Hi, How can I validate date in model class Thanks. Sainaba. -- Posted via http://www.ruby-forum.com/.