[Rails] Programmatically copying ActiveModel validators from one model to another?

2014-04-26 Thread John Feminella
I'm writing a library that will require programmatically copying validations from one model to another, but I'm stumped on how to pull this off. I have a model that is an `ActiveModel::Model` with some validation: class User < ActiveRecord::Base validates :name, presence: true end

[Rails] How do I prevent Rails from trying to load the application for every Rake task?

2012-02-05 Thread John Feminella
Here's what the default Rails 3 Rakefile looks like: require File.expand_path('../config/application', __FILE__) MyApp::Application.load_tasks This does the following: * Loads my Rails application. This takes around 15 seconds. Most of this time is spent on the `Bundler.require`; Rails i

[Rails] Can you extend an association, but only for a specific instance?

2012-01-19 Thread John Feminella
ActiveRecord allows an association to be extended, as in: module FindWeeklyExtension def weekly(start) where("created_at > :t1 and created_at < :t2", :t1 => start, :t2 => start + 7.days ) end end class Author has_many :posts, :extend => FindWeeklyExte

Re: [Rails] how it works with Proc object?

2011-09-06 Thread John Feminella
ke this: ``` def test(&block) call &block and evaluate it end ``` That means that if you call #test with { p "a" }, then #test's implementation is effectively ``` def test p "a" end ``` ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.l

Re: [Rails] Best way to model rules in Rails?

2011-09-06 Thread John Feminella
> So surely a Contract has many Conditions (and that relationship is > polymorphic: DurationCondition, CreditCheckCondition, etc)? Correct. > And you > can validate_associated conditions. That way each condition checks > itself for validity. The contract shouldn't have anything to do with > its c

[Rails] Best way to model rules in Rails?

2011-09-06 Thread John Feminella
I have a Contract class, along the lines of: class Contract < ActiveRecord::Base validates_associated :signatures validates_presence_of :title # ... end One or more Conditions might apply to a Contract. Each Condition imposes some kind of restriction or rule on the Contract it applies to. T

Re: [Rails] Re: Simplify code on method about 4 models

2011-08-10 Thread John Feminella
Sorry, typo. Should be: ``` Account has_many :users, :through => :memberships User has_many :accounts, :through => :memberships Membership belongs_to :user belongs_to :account has_one :role # agent, owner, etc. ``` -- John Feminella Principal Consultant, BitsBuilder LI

Re: [Rails] Re: Simplify code on method about 4 models

2011-08-10 Thread John Feminella
# agent, owner, etc. ``` ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Wed, Aug 10, 2011 at 16:20, Leonel *.* wrote: > Thanks Fred! > > The reason of this setup (might need some adjusting) is that

Re: [Rails] What does using a lambda in rspec tests accomplish?

2011-07-25 Thread John Feminella
t can't. By the time you reach the third line, the old value of `before.val` is gone forever. ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Mon, Jul 25, 2011 at 07:12, 7stud -- wrote:

Re: [Rails] RoR for a front end web designer

2011-07-22 Thread John Feminella
> Books are great, I would add to your list Tobie Fernandez's The Rails 3 Way. Just a small correction here: the author is "Obie Fernandez". ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/

Re: [Rails] Restful Users

2011-07-18 Thread John Feminella
Isn't that just the `GET /users` path? ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Mon, Jul 18, 2011 at 21:12, Tyrel R. wrote: > I just finished my authentication for my user model and

[Rails] Rails 3 subdomain routing

2011-07-08 Thread John Feminella
hi, On my site, if a user comes in through a mobile subdomain (say, `mob.example.com`), I want to change the request format of that request to be ":mobile". What's the most sensible way to do this? ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.c

Re: [Rails] error of DEPRECATION WARNING

2011-07-06 Thread John Feminella
Shoulda is telling you that you should write "should have_many", not "should_have_many". ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Wed, Jul 6, 2011 at 22:40, Yennie wrote: >

Re: [Rails] Re: when to add validations to database

2011-07-04 Thread John Feminella
7;t think this is true even if you had full control over the database. in practice, there are some migrations that can't be written without hitting the database directly, thus bypassing some models. -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: ht

Re: [Rails] Re: Hash each where

2011-06-30 Thread John Feminella
only_new_entries = array_of_hashes.select { |h| h[:status] == "new" } ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Thu, Jun 30, 2011 at 09:07, Sebastian wrote: > Sorry, > > yes

Re: [Rails] Redis persistent values missing

2011-06-21 Thread John Feminella
s probably gone for good, but youmay be able to ask the redis folks for help on this. ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Tue, Jun 21, 2011 at 18:35, David wrote: > Hi, > I am using red

Re: [Rails] How much logic should I add to my ActiveRecords

2011-06-20 Thread John Feminella
> def expired? >  Time.now - self.created_at > 10.days     # or whatever the period is > end fwiw, I prefer to write that sort of condition as: = def expired? self.created_at < 10.days.ago end = ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.

[Rails] Re: Spiffying up a group-by query through ARel?

2011-06-19 Thread John Feminella
Also: the query I have now still isn't quite right since it returns empty Categories (the LEFT JOINs need to be JOINs), which is another reason I'm interested in taking a look at it in ARel. On Sun, Jun 19, 2011 at 21:38, John Feminella wrote: > In my application, a Store belongs

[Rails] Spiffying up a group-by query through ARel?

2011-06-19 Thread John Feminella
In my application, a Store belongs to a Business, a Business has many Stores, and each Business has many Categories through Categorizations. I would like to return a list of Categories mapped to the number of Stores in that category. For example, suppose that we have: business 1: in categorie

[Rails] Most idiomatic way to identify and modify an association directly

2011-06-14 Thread John Feminella
Suppose that we have Radio Stations which play Songs by means of a License. === class Song has_many :licenses has_many :radio_stations, :through => :licenses end class RadioStation has_many :licenses has_many :songs, :through => :licenses end class License belongs_to :radio_station