Josh on Rails
2006-Feb-02 16:12 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
Hi all -- The simple question is: How do I set different validations for the same Model, when accessed in different Controllers? Here''s the scenario: I have a store/cart app, with a customer-facing shopping cart, and a typical Admin side. The Admin side also has an Order Entry component, where our staff can enter orders received by fax, telephone, etc. Both the customer-facing cart and the Admin-side Orders would use the same model (same underlying data) for customer information - billing, shipping, etc. However, the Admin side is intended to be a bit more flexible than the customer-facing side. For example, we might take international orders by phone, but not over the Web. Or we might allow payment with PO/check/cash by an Admin-side order, but not from a Web order. If I set something like "validate :credit_card_number" in the Model, it will trigger on the Admin side, requiring a credit card, where I''d prefer to allow a blank credit card. How do I set per-Controller validation? Or, is there another, more idiomatic way to approach this altogether? -- Joshua
Simon Robson
2006-Feb-02 16:33 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
Hi Josh, You might want to take a look at some of the ideas in this great article by Scott Baron: http://lunchroom.lunchboxsoftware.com/pages/specifications/ I''m facing some similar issues in a project at the moment, and the key concept is shifting business-logic (or multi-model, context dependent) restraints out of the largely single-model validation framework in rails. Hope the links provides food for thought. Simon Josh on Rails wrote:> Hi all -- > > The simple question is: How do I set different validations for the same > Model, when accessed in different Controllers? > > Here''s the scenario: I have a store/cart app, with a customer-facing > shopping cart, and a typical Admin side. The Admin side also has an > Order Entry component, where our staff can enter orders received by fax, > telephone, etc. Both the customer-facing cart and the Admin-side Orders > would use the same model (same underlying data) for customer information > - billing, shipping, etc. > > However, the Admin side is intended to be a bit more flexible than the > customer-facing side. For example, we might take international orders by > phone, but not over the Web. Or we might allow payment with > PO/check/cash by an Admin-side order, but not from a Web order. > > If I set something like "validate :credit_card_number" in the Model, it > will trigger on the Admin side, requiring a credit card, where I''d > prefer to allow a blank credit card. How do I set per-Controller > validation? Or, is there another, more idiomatic way to approach this > altogether? > > > > > -- Joshua > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Alain Ravet
2006-Feb-02 16:56 UTC
[Rails] Re: How do I? Same Model, Different Controllers, Different Validations?
Josh Using 2 related models is the simplest way : class Cart < ActiveRecord::Base ... validations for the admin class PublicCart < Cart ... validations for everybody else Alain
Ben Munat
2006-Feb-02 19:23 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
Not getting anything at that link... are you sure it''s correct? b Simon Robson wrote:> Hi Josh, > > You might want to take a look at some of the ideas in this great article > by Scott Baron: > http://lunchroom.lunchboxsoftware.com/pages/specifications/ > > I''m facing some similar issues in a project at the moment, and the key > concept is shifting business-logic (or multi-model, context dependent) > restraints out of the largely single-model validation framework in rails. > > Hope the links provides food for thought. > > Simon > > > Josh on Rails wrote: > >> Hi all -- >> >> The simple question is: How do I set different validations for the >> same Model, when accessed in different Controllers? >> >> Here''s the scenario: I have a store/cart app, with a customer-facing >> shopping cart, and a typical Admin side. The Admin side also has an >> Order Entry component, where our staff can enter orders received by >> fax, telephone, etc. Both the customer-facing cart and the Admin-side >> Orders would use the same model (same underlying data) for customer >> information - billing, shipping, etc. >> >> However, the Admin side is intended to be a bit more flexible than the >> customer-facing side. For example, we might take international orders >> by phone, but not over the Web. Or we might allow payment with >> PO/check/cash by an Admin-side order, but not from a Web order. >> >> If I set something like "validate :credit_card_number" in the Model, >> it will trigger on the Admin side, requiring a credit card, where I''d >> prefer to allow a blank credit card. How do I set per-Controller >> validation? Or, is there another, more idiomatic way to approach this >> altogether? >> >> >> >> >> -- Joshua >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Giles Bowkett
2006-Feb-06 23:25 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
Any place besides the book he mentions ("Domain-Driven Design") where I can find more background about this? It''s an interesting article but I can''t figure out if he intends specifications to exist solely for the purpose of making validation easier, or if there''s more to it than that. Is the goal just to decouple validation from the specification you''re validating against? On 2/2/06, Simon Robson <simon@intropica.com> wrote:> Hi Josh, > > You might want to take a look at some of the ideas in this great article > by Scott Baron: > http://lunchroom.lunchboxsoftware.com/pages/specifications/ > > I''m facing some similar issues in a project at the moment, and the key > concept is shifting business-logic (or multi-model, context dependent) > restraints out of the largely single-model validation framework in rails. > > Hope the links provides food for thought. > > Simon > > > Josh on Rails wrote: > > Hi all -- > > > > The simple question is: How do I set different validations for the same > > Model, when accessed in different Controllers? > > > > Here''s the scenario: I have a store/cart app, with a customer-facing > > shopping cart, and a typical Admin side. The Admin side also has an > > Order Entry component, where our staff can enter orders received by fax, > > telephone, etc. Both the customer-facing cart and the Admin-side Orders > > would use the same model (same underlying data) for customer information > > - billing, shipping, etc. > > > > However, the Admin side is intended to be a bit more flexible than the > > customer-facing side. For example, we might take international orders by > > phone, but not over the Web. Or we might allow payment with > > PO/check/cash by an Admin-side order, but not from a Web order. > > > > If I set something like "validate :credit_card_number" in the Model, it > > will trigger on the Admin side, requiring a credit card, where I''d > > prefer to allow a blank credit card. How do I set per-Controller > > validation? Or, is there another, more idiomatic way to approach this > > altogether? > > > > > > > > > > -- Joshua > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Giles Goat Boy http://gilesmakesmusic.blogspot.com http://gileswritescode.blogspot.com
Ben Munat
2006-Feb-07 01:02 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
He''s talking about the Specification Pattern, in which you create an object that handles verification of some group of objects requirements. Here''s a paper by Martin Fowler and Eric Evans about it (Evans used a bunch of stuff from this in his chapter in the book): http://www.martinfowler.com/apsupp/spec.pdf There''s also the site for the book: http://domaindrivendesign.org/ which unfortunately never really took off, but it does have a 40-page .doc download that has summaries of the patterns in the book. There''s also this site: http://patternshare.org/default.aspx/Home.DDD.HomePage with an annoyingly small font size and short summaries of the patterns. But basically, you should just get the book... at least if you''re going to be doing fairly big applications. Well, it''s an interesting read regardless. b Giles Bowkett wrote:> Any place besides the book he mentions ("Domain-Driven Design") where > I can find more background about this? It''s an interesting article but > I can''t figure out if he intends specifications to exist solely for > the purpose of making validation easier, or if there''s more to it than > that. Is the goal just to decouple validation from the specification > you''re validating against? > > On 2/2/06, Simon Robson <simon@intropica.com> wrote: > >>Hi Josh, >> >>You might want to take a look at some of the ideas in this great article >>by Scott Baron: >>http://lunchroom.lunchboxsoftware.com/pages/specifications/ >> >>I''m facing some similar issues in a project at the moment, and the key >>concept is shifting business-logic (or multi-model, context dependent) >>restraints out of the largely single-model validation framework in rails. >> >>Hope the links provides food for thought. >> >>Simon >> >> >>Josh on Rails wrote: >> >>>Hi all -- >>> >>>The simple question is: How do I set different validations for the same >>>Model, when accessed in different Controllers? >>> >>>Here''s the scenario: I have a store/cart app, with a customer-facing >>>shopping cart, and a typical Admin side. The Admin side also has an >>>Order Entry component, where our staff can enter orders received by fax, >>>telephone, etc. Both the customer-facing cart and the Admin-side Orders >>>would use the same model (same underlying data) for customer information >>>- billing, shipping, etc. >>> >>>However, the Admin side is intended to be a bit more flexible than the >>>customer-facing side. For example, we might take international orders by >>>phone, but not over the Web. Or we might allow payment with >>>PO/check/cash by an Admin-side order, but not from a Web order. >>> >>>If I set something like "validate :credit_card_number" in the Model, it >>>will trigger on the Admin side, requiring a credit card, where I''d >>>prefer to allow a blank credit card. How do I set per-Controller >>>validation? Or, is there another, more idiomatic way to approach this >>>altogether? >>> >>> >>> >>> >>>-- Joshua >>>_______________________________________________ >>>Rails mailing list >>>Rails@lists.rubyonrails.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > > -- > Giles Goat Boy > > http://gilesmakesmusic.blogspot.com > http://gileswritescode.blogspot.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Giles Bowkett
2006-Feb-07 17:40 UTC
[Rails] How do I? Same Model, Different Controllers, Different Validations?
Thanks Ben -- I''m going through the white paper, it looks pretty good. On 2/6/06, Ben Munat <bent@munat.com> wrote:> He''s talking about the Specification Pattern, in which you create an object that handles verification of some group of > objects requirements. > > Here''s a paper by Martin Fowler and Eric Evans about it (Evans used a bunch of stuff from this in his chapter in the book): > > http://www.martinfowler.com/apsupp/spec.pdf > > There''s also the site for the book: > > http://domaindrivendesign.org/ > > which unfortunately never really took off, but it does have a 40-page .doc download that has summaries of the patterns > in the book. > > There''s also this site: > > http://patternshare.org/default.aspx/Home.DDD.HomePage > > with an annoyingly small font size and short summaries of the patterns. > > But basically, you should just get the book... at least if you''re going to be doing fairly big applications. Well, it''s > an interesting read regardless. > > b > > > Giles Bowkett wrote: > > Any place besides the book he mentions ("Domain-Driven Design") where > > I can find more background about this? It''s an interesting article but > > I can''t figure out if he intends specifications to exist solely for > > the purpose of making validation easier, or if there''s more to it than > > that. Is the goal just to decouple validation from the specification > > you''re validating against? > > > > On 2/2/06, Simon Robson <simon@intropica.com> wrote: > > > >>Hi Josh, > >> > >>You might want to take a look at some of the ideas in this great article > >>by Scott Baron: > >>http://lunchroom.lunchboxsoftware.com/pages/specifications/ > >> > >>I''m facing some similar issues in a project at the moment, and the key > >>concept is shifting business-logic (or multi-model, context dependent) > >>restraints out of the largely single-model validation framework in rails. > >> > >>Hope the links provides food for thought. > >> > >>Simon > >> > >> > >>Josh on Rails wrote: > >> > >>>Hi all -- > >>> > >>>The simple question is: How do I set different validations for the same > >>>Model, when accessed in different Controllers? > >>> > >>>Here''s the scenario: I have a store/cart app, with a customer-facing > >>>shopping cart, and a typical Admin side. The Admin side also has an > >>>Order Entry component, where our staff can enter orders received by fax, > >>>telephone, etc. Both the customer-facing cart and the Admin-side Orders > >>>would use the same model (same underlying data) for customer information > >>>- billing, shipping, etc. > >>> > >>>However, the Admin side is intended to be a bit more flexible than the > >>>customer-facing side. For example, we might take international orders by > >>>phone, but not over the Web. Or we might allow payment with > >>>PO/check/cash by an Admin-side order, but not from a Web order. > >>> > >>>If I set something like "validate :credit_card_number" in the Model, it > >>>will trigger on the Admin side, requiring a credit card, where I''d > >>>prefer to allow a blank credit card. How do I set per-Controller > >>>validation? Or, is there another, more idiomatic way to approach this > >>>altogether? > >>> > >>> > >>> > >>> > >>>-- Joshua > >>>_______________________________________________ > >>>Rails mailing list > >>>Rails@lists.rubyonrails.org > >>>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails@lists.rubyonrails.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > > > -- > > Giles Goat Boy > > > > http://gilesmakesmusic.blogspot.com > > http://gileswritescode.blogspot.com > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Giles Goat Boy http://gilesmakesmusic.blogspot.com http://gileswritescode.blogspot.com