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
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
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
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
> 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
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
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
# 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
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:
> 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/
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
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
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:
>
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
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
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
> 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.
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
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
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
20 matches
Mail list logo