similar to: Override automatic accessor for reference field in model

Displaying 20 results from an estimated 9000 matches similar to: "Override automatic accessor for reference field in model"

2006 Aug 20
0
Re: Problem with overriding rails accessor methods
On 8/20/06, Paul Corcoran <prcorcoran-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote: > > > Hello all, > > I just encountered something that is not what I would expect. I > overrode an accessor method in my model class and within this method I > did a "super" call which failed. Of couse my real method would be doing > more but here is the basic code that
2006 Jan 02
3
Altering the accessor of an association collection
I want to be able to do something like this (for example): class Person < ActiveRecord::Base has_many :friends def friends(living_in = :uk) # filter based on parameters here end end Is there any way I can redefine the accessor for an association whilst still being able to get the values? Basically, I''m looking for an equivilent of read_attribute() for associations. --
2006 Feb 19
0
Handling nil attributes in views
The problem at hand is how to handle missing (but not required) refs to other objects when working in a view (that was not clear - gimme a minute:-). There has been some discussion of this on the wiki, but I was wondering what others thought about handling this. I have class A that belongs_to class B, and I want to display an attribute of B in the view, so I do something like the following:
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 Jan 14
0
Overriding column accessors?
Hi, Is it possible to override the default accessors that are created by Rails? For instance I had this User object which has the column headings "password" and "salt" in its SQL table. I did manage to override the setter accessor for password by using def password=(new_password), but when I tried doing the same for the reader by using a def password method (to return a
2006 Feb 22
0
Rewriting attribute accessors?
I''m new to Rails and so was wondering if the following strategy is a good idea. Background: I''m writing a eCommerce application which has a Product model and an Option model, they are setup with a has_and_belongs_to_many relationship. The Product model features the ''base'' attributes of the product and then the shopkeeper *can* add one or more Options that
2011 Apr 01
0
[GIT PULL] elflink cmdline
Hi, The following patches are just copying some functionality that exists in the asm cmdline code into the C version. There's still a few more things to do but we're getting there. The following changes since commit 8c576f1fe03e34879921311f46613a35c6530000: Merge remote-tracking branch 'mfleming/for-hpa/elflink/fix-compiler-warnings' into elflink (2011-03-16 12:53:58 -0700)
2006 Oct 25
0
has_one & foreign_key - generating bad SQL
- MODEL - class Document < ActiveRecord::Base has_one :user, :class_name => "User", :foreign_key => "fkey", :conditions => "user = ''NAME''" end - GENERATED SQL (per the .log) - SELECT FIRST 1 * FROM table_name WHERE (table_name.fkey IS NULL AND (user_id = ''NAME'')) What I can''t figure out is
2009 Nov 09
3
How can I improve a Ruby on Rails code that hast a lot of SQL as strings?
Hello Railists, I have a piece of Ruby on Rails code that has a complex SQL query (well, not that complex, but as far as I know beyond the ORM capabilities) and for my taste it has too many strings and harcoded values. I''d like to improve it as much as possible, so my question is open ended, what else can I do to improve it? Some particular issues I have - Is there a way to get a table
2010 Nov 17
2
Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'
Hi there, I''d like to choose between an "static" and "dynamic" access of a reference class field, say ''a''. myObj <- getRefClass("Blabla")$new() Static: myObj$a Dynamic: myObj$a.get() where the function retrieves the data from a database (or some other location), stores it to a buffer and
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 Jun 26
2
DRY up selects in view
Here''s what I''ve got: <% @fields.each do |field_name| %> <tr> <td> <%= field_name.humanize %> </td> <td> <% unless field_name =~ /_id$/ %> <%= form.text_field field_name, :size => 40 %> <% else %> <%= select(:vendor, field_name, State.find(:all, :order
2006 Jun 13
0
Best way to format attributes during visualization/editing
Hi to everyone, My name''s Carmine and I''m a rails newbie. So, here''s my newbie question :) I have a model with one attribute named "kind" of type integer. This attribute can assume values within the range [0..5]. Each value has a "verbose" representation e.g.: 0 => grain, 1 => liquid ... To visualize the verbose representation I''ve
2006 May 03
2
Using a helper within another helper?
I am trying to push some view logic into a helper. The thought is that this is a step towards having the business logic in the helper rather than the view. However, I''m essentially wrapping the checks around an eventual call to date_select(). The problem I''m having is that the application complains that it doesn''t know about date_select(). I''m sure (or
2007 Nov 18
0
Trouble overriding default accessor/mutator
I have a database column storing a duration value as a number of seconds, but I''d like users to be able to see it and edit it as a time value. I am trying to override the default accessor/mutator for the attribute and do the conversions there, using something that looks like: def duration Time.at(self[:duration].to_i).getutc end def duration=(value) self[:duration] = value.to_i
2006 Jun 17
0
Dynamic forms containing collections
Hiall, I have the following problem: I need to use forms containing collections (i will call them FCC), and I want to construct them dynamically, as I need to deal with quite large forms (more than 600 input fields). The variables @model_name and @field_name contain the proper model and field names as strings, which is enough for "normal" form input fields. (i.e. the "if
2010 Jul 26
1
form date helper with text year
I have a date where the year range is more then I want to define in a select_date scaffold generated year range. My idea was to have the year entered as a text field and the month and day using something like: <%= select_month @person.born,:prefix => :person ,:field_name => "born(2i)" %> <%= select_day @person.born,:prefix => :person , :field_name =>
2015 Jun 20
1
Xapian with Json
Hi ! I?m newbie with Xapian ! I?m looking for the best way to index json data to be able to search by name/value pair and Full Text Search using only Xapian. I did haven?t success to found a complete or a good documentation about json index and search. Do you know some documentation about ? Another problem that I have is that: In the same name/value pair sometimes I have different data types
2006 Feb 02
5
access controller var within model
I need to access params[:field_name] from within my Model. @params[:field_name] isn''t working?
2006 Oct 05
4
search results autocompletion
Dear list, I ''m using a text input field with autocompletion . The suggestions come from a ferret index which is created by getting all the terms belonging to other indices. Here is the code: class Suggestion attr_accessor :term def self.index(create) [Person, Project, Orgunit].each{|kl| terms = self.all_terms(kl) terms.each{|term| suggestion =