[Rails] Re: Re: run script after initialize

2012-05-07 Thread Guillem Vidal
Jeremy Walker wrote in post #1059759: On 6 May 2012 22:13, Guillem Vidal li...@ruby-forum.com wrote: You could just reopen ActiveRecord::Base. Create a new initializer (a http://www.ihid.co.uk end end OK, so two more suggestions: 1) Use an after_initialize block in your config

[Rails] Re: run script after initialize

2012-05-07 Thread Guillem Vidal
Rodrigo Vieira wrote in post #1059873: Well, I'd create a file and put it in /lib and include/initialize that file in the config.ru file before the actual app initialization (run YourApp::Application). That worked! The problem is that this is only working when rails app starts, not on rake

[Rails] run script after initialize

2012-05-06 Thread Guillem Vidal
hi there!! I'm just trying to run a script that adds certain methods to all ActiveRecord::Base descendants, but what happens is that it seems that all models are loaded after the application runs ActiveRecord::Base.send(:descendants).each do |subclass| #do stuff end

[Rails] Re: run script after initialize

2012-05-06 Thread Guillem Vidal
Jeremy Walker wrote in post #1059748: On 6 May 2012, at 20:22, Guillem Vidal li...@ruby-forum.com wrote: ActiveRecord::Base.send(:descendants) and ActiveRecord::Base.send(:subclasses) is allways empty []. I've tried it on config/environment.rb and config/application.rb with no success, can

[Rails] Re: run script after initialize

2012-05-06 Thread Guillem Vidal
? || klass.ancestors.include?(ActiveRecord::Base) klass.reflect_on_all_associations.each do |association| klass.send(:define_method, #{association.name.to_s}_tokens) do read_attribute(__method__) end end end It raises connection not stablished. Guillem Vidal

[Rails] Re: autocomplete word by word

2012-05-06 Thread Guillem Vidal
rubix Rubix wrote in post #1059751: Hi, I am trying to implement an autocomplete form with rails, I used jquery in a first version, to suggest phrases to user and it worked Now I am trying to have a service of autocomplete word by word, it means when the user it typing in the text area, I

[Rails] custom lib for datepicker

2012-04-30 Thread Guillem Vidal
Hi there, I'm doing an own library to manage datetimes depending on locales, to deal with the formats of datetimes. I actually overrides the default assign methods to made strptime. I've made the following: http://ideone.com/PXYl8 something is wrong when trying to access on I18n.t, the scope

[Rails] has_many :through behaviour trouble

2011-08-22 Thread Guillem Vidal
Hi there! I have the following classes, but I don't undersant why, when I try to create some class Wishlist ActiveRecord::Base has_many :activated_user_wishlists, :class_name = UserWishlist, :conditions = {:registered = true} has_many :users_registered, :through = :activated_user_wishlists,