similar to: module_eval and scope question

Displaying 20 results from an estimated 2000 matches similar to: "module_eval and scope question"

2006 Mar 13
1
adding custom cache field
Hello, I needed to add custom cache field for one of my application. I thought I will share the code showing how to do this. This code below creates and maintain a custom cache field, for keeping track of totals. Say, you have accounts, and for each account there are transactions (either deposit/withdrawal), and one will like to keep track of the total balance for an account. So, let there be a
2012 Sep 11
1
define_method vs module_eval
Rails code: Accessors.send :define_method, :"default_#{name}", &block Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1    def #{name}    -ISKimRw02aC5oVgD8gxYQQ@public.gmane.org(:#{name}, [])    end    def #{name}=(value)    value = value.present? ? Array(value) : default_#{name}    _set_detail(:#{name}, value) if value != @details[:#{name}]    end  
2006 Jul 27
9
Introspecting validates_presence_of
Hello people, I''d like to detect whether an attribute of a model has vaildates_presence_of applied to it so I can automatically apply a mandatory (*) to the field...it doesn''t look easy...any ideas? Cheers, -- Dan Webb http://www.danwebb.net
2006 Feb 03
1
modifying scaffold method
I''ve made the following changes to scaffolding.rb. Is it possible to put those changes into some type of a plugin or helper or something, instead of directly modifying the Rails source? (and, btw, I think pagination should be removed from scaffolding. And deletes should only happen on post requests. That''s essentially what I''ve changed). Thanks, Joe Index:
2006 Jul 22
1
How to debug this
Hello,I get this message and I don''t know how to interprete this.I think it has to do with plural tables and singular referencesThanks for any help!Jim======================================================================================uninitialized constant SubjectRAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace
2006 Jan 09
1
Cooky Cookies
Hi All, I have a problem with the stemming(?) in rails. I have a table cookie and a Cookie model which I have generated a scaffold for. The problem is that rails starts looking for a file that it calls "cooky.rb", this must be some kind of misunderstanding between me and rails, but how do I correct it? Other scaffolds work just fine. /Hugo NameError in Cookie#index uninitialized
2006 Jul 26
1
Scaffolding Problems
Hi.. Im a brand new ruby on rails developer, and when i make a scaffold and navigate to the it, i get an error that looks like this. ----------------------------------------------------------------- NameError in PagesController#list uninitialized constant Page RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace
2006 Jan 10
1
Cooky cookies causes trouble
Hi All, Yesterday wrote about my troubles with naming a table and model cookies and cookie respectively. I know that everybody hates the newbie screaming bug as soon as he encounters behaviour he doesn''t understand. But I''ve reproduced the error in the simplest application possible, and dare therefore say that this quite possible could be a bug in Rails. Database: CREATE TABLE
2006 Jun 14
5
uninitialized constant error after scaffold on new Windows XP environment
I am attempting to get a working Rails programming environment setup working under XP with MySQL, RadRails and Webrick. I have been using my PowerBook but need to working on Windows environment too. I have basic functions of Ruby and Rails going. I created a really simple table and generated the scaffolding. The server starts just fine. I can browse the database succesfully in RadRails. The issue
2006 Jul 02
7
How can I intercept attribute calls?
Hi. I have two types of fields in my database, e.g. "name" and "name_ru". First one is a user''s name in english and the second one is in russian. I want to intercept calls like "c.name" and add "_ru" to it if current language is russian (I have my own Locale class like n Globalize). So I want such thing: -- Locale.set("en-US") c.name
2005 Dec 21
1
Table called applications - causes stack overflow?
Having worked through Four Days on Rails and the book Agile Web Development with Rails I decided it was time to start a live project. I have an existing application with MySQL database, so I modified the schema to use Rails standard column names. The main table was named ''applications''. ruby script/generate scaffold Application Admin results a stack overflow
2007 Jan 17
1
include ClassMethods in plugins
Why is that in so many plugins I see people using (including acts_as_taggable by DHH): # init.rb ActiveRecord::Base.send(:include, ActiveRecord::Acts::SomeModule) # lib/some_module.rb module ActiveRecord module Acts module SomeModule def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_something # code
2006 Jun 07
1
validates_presence_of in a mixed-in module?
Anyone got any idea of how to use built-in validation methods in a mixed-in module. What I''ve got at the moment is each class that needs ranking methods includes [the module] Ranking. Then the module Ranking has a bunch of instance methods and a submodule ClassMethods. The ClassMethods in this are mixed in to the class with self.included. So far so good. But I want the module to
2008 May 28
3
Plug-in support for Camping Apps
# camping_plugin.rb # plug-in support for Camping Apps # require ''lib/camping_plugin'' # override R helper method to your liking :-) module Camping module PluginHelpers def R_with_module(c,*g) p,h=/\(.+?\)/,g.grep(Hash) g-=h raise "bad route" unless u = c.urls.find{|x| break x if x.scan(p).size == g.size &&
2007 Jun 27
5
Filter Ordering in Edge Rails (Rev 7143)
Filter chaining appears to behave in differently than Rails 1.2.x. It seems that I''m getting a lot of errors along the lines of: ActionController::ActionControllerError: filter #<ActionController::Filters::ClassMethods::BeforeFilterProxy:0x322f468 @filter=#<ActionController::Filters::ClassMethods::SymbolFilter: 0x322f4b8 @filter=:login_required>> was in the wrong place!
2006 Apr 18
4
Mixin variables
I''ve created an access control module that I''m including in several different controllers. Everything works fine, but I want to allow each controller to override the default login page with something like this: set_login_pages :secure => ''my_login'' In my module, I''ve set up the set_login_pages method like this: def self.included(base)
2005 May 14
2
ActiveRecord::Associations::ClassMethods Documentation Issue
I''m curious, but isn''t this example in the documentation for ActiveRecord::Associations::ClassMethods somewhat counter-intuitive? The SQL DDL is correct for the way it''s used in the models. But isn''t it more logical that an author would have many posts, rather than many authors having one post? From
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all I have the following plugin code: module IncenseCrud def self.included(base_class) base_class.extend(ClassMethods) end module ClassMethods def performs_incense_crud def index list return render(:action => ''list'') end end end end In init.rb I have the following: require File.dirname(__FILE__) +
2006 Jun 03
1
Can I tell if the associated record is new in a belongs_to save?
In a belongs_to association, is there a way to tell if the associated object was newly created? Hopefully this will explain my question: A Firm class declares has_many<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000530>:clients and a client class declares
2007 Nov 27
1
Plugin - How to access object from instance method
Quick question: Given a basic plugin... how can I access an object that I instantiated in the acts_as method from an instance method? Probably some sort of accessor... but where? def self.included(base) base.extend ClassMethods end module ClassMethods def acts_as_test object = Object.new ## This object needs to be accessible from the Instance Methods end include