similar to: Form validation - keepin correct fields displayed on refresh

Displaying 20 results from an estimated 4000 matches similar to: "Form validation - keepin correct fields displayed on refresh"

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 Jul 12
1
validate method not getting called?
Here''s a snippet of my model: validates_presence_of :from_name, :from_email, :reply_name, :reply_email, :eSubject protected def validate puts "Calling: #{target_list_ids}" errors.add_to_base("You must choose at least one target list for this job") if self.target_list_ids.nil? end It appears that the validates_presence_of are being called just fine,
2006 Jul 13
4
Does text_field go directly to attributes hash in AR object?
All, I''m having a hell of a time figuring out what is going on here. I''m trying to override one of my getters so that I can format it a certain way in my form. But I can''t seem to get text_field to call the appropriate method on my object. So here''s my getter: public def FAX fax = read_attribute(:FAX) puts fax
2006 Apr 20
5
Integrating with Legacy Databases
This seems like it must have been asked before - I really _did_ try to find it in the archives, so my apologies if it''s already out there. Utilizing ActiveRecord, I would like to specify a prefix for the column names in my table. For example, in ''Recipe 16 Integrating with Legacy Databases'' (Rails Recipes, from PragProg, by Fowler) they deal with integration with a
2006 Jul 03
4
text_field doesn''t call overridden ActiveRecord getters
All, In a template, I have <%= text_field :target_list, :DateReceived, { :title => ''uploaded_at'', :class => ''target_list_info'', :disabled => ''true'' } %> Here is the DateReceived method on my
2006 Mar 14
5
Column aliasing in ActiveRecord?
Anybody know of a way to alias a column in ActiveRecord such that you could reference it via a different symbol in your view for view purposes? Like my column is named X but I want to display it as Y and maybe I have an accessor named Y set up on the model so that when I "call" Y from the view (and controller?) I''m actually manipulating the column X? Hope that makes sense.
2005 Dec 23
10
Extending model
Hi, I''m looking for a way to extend one of my models to allow some level of abstraction between what goes into it and how it is stored. For example, say I have a Product and I want to set it''s price. A person using the website will type the price in euros. Internally, I''d like to store the price as an integer value of cents. I can currently do this with some ugly code
2006 Jul 17
6
Best Practices: Splitting the "view model" from AR model
All, I''m starting to see view state information creeping into my model class. For example, I have text fields in my view that need to be set a certain way depending on whether or not a checkbox is checked. And while the values of these text fields ultimately do represent database columns that are related to the backing AR object, the text_field values also represent attributes on a
2009 Sep 23
5
Overriding AR read/write_attribute - Overridden write_attribute Is Never Called
Could someone explain this? #config/initializers/ar_attributes.rb module ActiveRecord module AttributeMethods alias_method :ar_read_attribute, :read_attribute def read_attribute(attr_name) p "read_override" ar_read_attribute(attr_name) end alias_method :ar_write_attribute, :write_attribute def write_attribute(attr_name, value)
2006 Feb 06
7
Delaying initialization of associations until first access
Guys, Say I have the following: ----- class Person < ActiveRecord::Base has_one :house end class House < ActiveRecord::Base belongs_to :person attr_accessor :color end ----- Then I have the following code: ----- john = Person.new john.house.color = "Blue" john.save ----- What I would like to have happen, is that on first call to john.house, if house hadn''t been
2010 Jul 19
3
ActiveRecord override
Would really appreciate it if someone could tell me why this is happening: I override ssn method of AR class so I can encrypt/decrypt to/from the db: class Person < ActiveRecord::Base def ssn=(value) write_attribute(:borrower_ssn, Crypto.encrypt(self.encryption_key, value)) write_attribute(:borrower_ssn_final_four, value[5,4]) end def ssn # this begin - rescue can be
2006 May 10
13
Issue in ActiveRecord generated reader methods
Hi all! I have come into a strange issue in Rails that I am hoping someone can shed some light. To make a very long story short, I have been researching how to override ActiveRecord::Base#read_attribute and write_attribute to perform security checks at the model level (influenced by the ModelSecurity generator). Shortly after implementing some code to check this behavior, I began to
2006 Aug 12
10
adding extra variable to a class, how to access it?
somple question here but pretty confusing on my side. i have a model towns that is mapped to my towns table. can i add an extra variable to the class and access it in my view? basicall what i am trying to do is return a list of towns, and next to each town, display a total number of what i have in each town. ive tried both attr_reader and @total but no avail. here is my view <% for
2006 Jan 10
5
IP Address
There''s got to be a simple answer: how do you get the IP address of a visitor in Ruby? Any help would be appreciated! -- Posted via http://www.ruby-forum.com/.
2006 May 09
11
model filter?
Hi All, Is there a way to filter / modify the output of a model class before it''s returned to controller/view that''s calling it? Example: I have a field phone_number which I always want to preformat using the number_to_phone() helper.... Any help is appriciated. Thanks! -- Posted via http://www.ruby-forum.com/.
2006 Jul 14
1
Weird validation problem
I have a field called Fax in my model. I store it as a 10-digit number with no other characters but I display it as a nicely formatted phone number. I have a validation on it like this: validates_format_of :Fax, :message => ''number should be formatted using (XXX) XXX-XXXX'', :with => /^\(\d{3}\)\ ?\d{3}-\d{4}$/ If I put 1234567890 (10 digits) in my field, the
2006 Jun 28
3
how do I validate currency format if I am storing in cents?
Hi all - To avoid floating point issues, I''ve decided to store monetary values in cents in the database. However, the user will enter these in dollars and cents. Two questions: 1) How do I do the validation for the currency format? It looks like ActiveRecord truncates the cents since it thinks the field type is a Fixnum. Am I forced to do validation in the controller? 2) Where
2006 Mar 18
9
Using <%= text_field %> within partials is problematic
All, Thanks for any help in advance. I have what I think is a very straightforward partial template and I can''t figure out why a text_field call within it doesn''t work. Here is my calling template: lists.rhtml <div id="target_lists"> <%= render(:partial => "target_lists", :collection => @target_lists) %> </div> In the partial
2006 May 30
5
Implementing HTTPS with WEBrick?
All, I would like to test some secure pages that I''m developing in my WEBrick-based development environment. I''ve done some research and it appears that I need to create a new command that will start a HTTPS based WEBrick server. Is this correct? Also, it appears that the https.rb module is not included with the WEBrick bundled in Rails. So, I will need to go get that
2006 Jul 10
8
Setup new data in the test database _after_ unit test runs
All, I want to run automated unit tests as part of my build. I am building to my test environment. Upon successful completion of all of my unit tests, I would then like to load some data (using a fixture, I imagine) into my test database that will act as fresh "system test" data for my users to play with. What is the best way to "load the standard system test/user acceptance