Greg Cosgrove

Joined

260 Experience
2 Lessons Completed
0 Questions Solved

Activity

Context: I'm working on an app for my job with strange requirements. Unfortunately, I have to maintain a data structure that's accessible to legacy CF applications that were originally designed for MSSQL. This has created an issue with model creep creating a lot of duplication. I can't use polymorphic association as I intended because of the legacy requirements. Thus, an app that could have had 20 models now has about 40.

The app has a lot of complex forms nested forms. Originally, I used accepts_nested_attributes_for, but this created validation and other problems because these forms are filled out progressively, not in one sitting. Data has to be validated piece by piece, even within a single model, then revalidated when the large form is completed.

I have abstracted the forms into Form Objects which works well in isolation. It also allows them to be reused in different places in the application. Unfortunately, I'm a little lost on how to aggregate these form objects into a single form and then pass data to the correct models. Any suggestions on strategies for this type of setup?

Posted in Page Specific Javascript

I had to do something like this in a specific circumstance. The solution I used was to create a unique body class for each page with interpolation.
In HAML:
%body{:class => "#{controller_name}-#{action_name}"}

In ERB:
<body class="<%= controller_name %>-<%= action_name %>">

Then I can just use the unique controller/action_name class to as a JS hook.