Join GitHub today
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
Cool Form Handling Overview I've started on the code here: https://github.com/joevandyk/monkey_forms For each of your html forms, you'd define a form handling class and include the Joe::Rocks::FormStuff module into it. This class is an interface / layer between ActionController and your Models (or whatever you are saving the data to). You could just send an email after they submit the form. After you submit the form, the values you submit are put into a gzip'd encoded cookie with json in it. This allows us to access the stuff you entered earlier. When you submit the next form (or the same form again), the values you submit are merged into the already-submitted form values that are saved in the cookie. So, you could submit an ajax request that only has one form attribute, and it would merge that one attribute with the other stuff you already submitted earlier. We use the standard ActiveModel::Validator stuff. The validation_scopes allows us to scope validations, so we'd only run the validations for certain attributes. ActiveModel would be the only dependency, by the way. The other files in this project are a taste of what this could look like. Still looking for a good project name, by the way. This is pretty similar to the Presenter Pattern as described by Jay Fields, by the way. http://blog.jayfields.com/2007/03/rails-presenter-pattern.html ??? WHY ??? Moving the form logic to a separate class has a ton of advantages: * Keeps the controller really simple. * Makes it easier to test. You can write tests directly against the form handling class. * Classes should do one thing. * You can have complex validations. * Your ActiveRecord models can probably become simpler. * Since the form handling logic is encapsulated into one class, you can use inheritance, modules, etc. * You want to move away from ActiveRecord? It's no problem -- just change how the form values are saved in the #save method.