Hello,

I've been giving a lot of thought to building a gem which puts more 
validation into the controllers and routing and removes it elsewhere. My 
conclusion was that I didn't need to build a gem, Rails in fact already has 
everything needed to accomplish this, however - I just need to change the 
default pattern it provides. I'd like to share my thoughts and receive 
yours - 

route validations, strong_parameters, and ActiveModel are sharing 
responsibility but are split across framework.

What if the instead of defining a single set of validation rules with a 
single class inheriting from AR per table, the default was to define 
several valid persistable-object states per table with a series of 
ActiveModel Prototypes.

What if setters, getters and validations were mixed in by virtue of these 
AM Prototype classes (I think default setters/getters are AR defined atm?). 
Further, the Prototype would guard persistence, like a state machine, since 
'create', 'save', 'update/patch', 'destroy' would not be defined/mixed-into 
every Prototype, only ones appropriate for the action.

Really, all this already exists - for instance, routing allows you to 
define regex's to match incoming parameters -- but how many people are 
using this? (that's a real question, I have no idea). Then we have 
controller level validation with strong_parameters. Then we have model 
level validation. Why not move all this into some form of Prototype which 
defines what keys are open, required, what they can, should, should not 
look like (type checking), etc?

This approach also has one cool side benefit - nicer introspection which 
can aid front end generators / frameworks.

I'm posting here cause I haven't thought this through fully and when I try 
to write out a DSL for this I start going off course -- but to my delight a 
few have touched upon these things in this thread, if I'm reading your 
thoughts correctly.

- Kunal

On Tuesday, November 25, 2014 9:09:57 AM UTC-5, Jason FB wrote:
>
> Rails core,
>
> I was wondering if Rails 5 has a discussed (or proposed) roadmap? A 
> growing chorus of developers are seeking ways to separate domain logic from 
> persistence logic at the model level. I was wondering from a bird’s-eye 
> perspective if the framework plans to adopt patterns to make that easier 
> (and more encouraged) to implement in the future?
>
> I tried to do a little googling for Rails 5 docs but I was unable to find 
> solid stuff.
>
> -Jason
>
>
> ----
>
> Jason Fleetwood-Boldt
> te...@datatravels.com <javascript:>
> http://www.jasonfleetwoodboldt.com/writing
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to