similar to: How To: Override Initialize

Displaying 20 results from an estimated 100000 matches similar to: "How To: Override Initialize"

2008 Apr 22
0
Overriding to_xml() - Why Does This Work?
In Chapter 5 of his book, Flexible Rails, Peter Armstrong''s leads his readers through an exercise to override the behavior of to_xml() in ActiveRecord objects so that :dasherize would be false by default. I found his solution inelegant. I came up with a more elegant one, and it seems to work. All I did was add the following to the very end of myapp/config/ environment.rb: class
2007 Oct 16
2
Where override model attribute names?
OK, so I get that ActiveRecord determines model attributes through reflection of the table schema. Handy for many cases, but not mine. I need to override that and provide my own mapping of attribute names to column names to use the mapped names throughout the application code. I''ve been poking around looking for where in AR''s hierarchy I can can inject this mapping, but
2008 Jan 21
1
ActionController majic gone bad
Overriding method missing in ActionController destroys magic even when passed back ie. def method_missing(method, *args) if some_condition do_something else #let rails handle it normally super(method,args) end end if I don''t over ride method missing then i can call a view without an action with the override i get a method missing error. MAJIC -- Posted via
2007 Aug 02
0
Overridding readonly attribute in custom form builder
Hi, I''ve created a custom form builder and overridden text_area so that all fields are readonly. There are a few instances that I would want an editable text_area, so I have tried to create an editable_text_area method. I have tried passing text_area(method, options.merge(:readonly=>false)) to the method, but it doesn''t work: the area is still not editable. Any
2006 Oct 27
5
Purpose of after_initialize in ActiveRecord?
All, I have a quick question - is the purpose of implementing after_initialize to allow custom attribute initialization for AR descendants? I have been overriding initialize whenever I require custom setup of my model classes, like so: def initialize(attributes = nil) super self.Status = ''G'' end So I have a couple of questions: 1) Could I achieve the same
2008 Nov 01
0
Overloading #initialize in a model
I''m using WhinyProtectedAttributes: http://henrik.nyh.se/2007/10/whiny-protected-attributes Say I have this model: class Person < ActiveRecord::Base attribute_accessible :name end If I then create a Person with an invalid attribute, an exception is raised. For example: Person.new :name => ''Bob'', :asdf => ''asdf'' What I''d like to
2007 Jan 05
0
ActiveResource cache using memcache-client
I''ve created this class that overrides methods for find,delete,destroy,reload, and save in activeresource. The code populates a local memcache daemon and uses that cache for future find requests. I''m posting it here to get whatever feedback people have. I''m most interested in the pro/con of inheritance over a mixin and how such a module might be tested. $ cat
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
2008 Mar 03
0
Overriding ActionController method in an app
i can''t seem to get this working... basically, i want to use a patch that was added to rails: http://dev.rubyonrails.org/changeset/8785 but i don''t want to have to upgrade past 2.0.2, and i don''t want to have to freeze rails inside the app. so i was hoping to override the methods in ActionController required to make the patch to my app only. i created a file called
2006 Dec 28
0
Localization using inheritance
Hi! I''m trying to implement localization using inheritance, i.e.: class ParentController < ApplicationController layout "mylayout" def initialize #do something end def index #do something end def search #do something end # ... end Controller do his job and render page using "mylayout" and views from "/view/parent"
2006 Jul 04
1
How to override ActiveRecord#base#destroy
Hello, I have a database table with a primary key not being a simple id but three columns. By overriding update() and create() I got Rails to work with that table quit good. Except for the destroy() action. From the resulting trace I can see that the old version of destroy() is called from transaction.rb. I think this lines might be the reason that I''m unable to override detroy():
2006 Nov 10
0
Override logger for large binary data
I''ve searched high and low and played around and couldn''t figure out how to override what the logger prints for a specific model (one that has many columns of multi-100K blobs). I ''tail -f log/development.log'' in a shell within emacs and it really doesn''t like the huge lines dumped out during saves/updates. So, I finally figured out that if I put the
2007 Sep 02
0
using database for validation
I''ve been playing around with the idea of using the database for model validation where possible (instead of duplicating that validation in rails). My first approach to this was to catch exceptions from save/ create and parse the errors, in my case from postgres, to turn them into something friendlier. Something like: def update create end def create begin super
2013 Oct 02
2
When overriding the registration controller from devise, is it possible to access the newly created
I''m trying to create a folder right after a user registers, so I override the create action on the registration controller (devise) but I don''t know how to access the newly created user in order to create the folder with it''s name to upload files later. So far I''ve got this: class RegistrationsController < Devise::RegistrationsController def new
2008 May 21
6
this.initialize has no properties error in Prototype Code
Hi All, I''m a super newbie with Prototype and am trying to implement my first solution using it. This is my code: var span = ''totalViews'' + video_id; var params = ''video_id='' + video_id; Ajax.Response(''trackVideo.php'', { method: ''post'', parameters: params, onSuccess: function(transport) {
2012 Sep 28
0
Overriding class_attribute writers and order of super/extend C.M./included block eval in ActiveSupport::Concern
I have: module MySpike extend ActiveSupport::Concern included do class_attribute :foobar, instance_writer: true end end But, I want to be able to override the class attribute writer and/or instance writer method to do something when the attribute is set via self.foobar = true before or after calling super to set the attribute. Unfortunately, I can''t find a clean way
2008 Oct 28
7
How to override one method of AssetTagHelper
I created a file ./lib/action_view/helpers/asset_tag_helper.rb and put in it only the method I want to override. like this module ActionView module Helpers #:nodoc: module AssetTagHelper def image_path(source) compute_public_path(source, ''images'') end end end end But as soon I try this all the others methods from the overriden module are not
2008 Feb 05
0
How do I override a method that's only invoked from a rake task
I want to override structure_dump in the MysqlAdapter class. (It doesn''t dump some stuff I need for my implementation and I''m extending it to do that.) I know how to override methods in application code. MysqlAdapter#structure_dump is called from the rake task db:structure:dump, and I can''t figure out where to put the overriding implementation so that it gets called
2006 Sep 06
1
Need to override database.yml settings for Capistrano run
All, Database: SQL Server 2000 SQLServer adapter in ODBC mode I have a Capistrano deploy script which fails when I run against my production DB. Apparently, this is the because the user that is set up for production has "guest" privileges in my SQL Server database and when Capistrano runs, instead of looking at the dbo.schema_info table (which has the correct version # - yes I
2006 May 10
2
What is wrong with this initialize method (code example)?
Here is my class: class Document < ActiveRecord::Base public def initialize puts "Called initialize..." super.initialize end This generates the following error: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occured while evaluating nil.initialize WTF? Wes -- Posted via