Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd go about this by having the user Model have a relationship with two profiles as suggested above as well. One "Approved" profile, and the one for editing that goes into your admin queue. </p> <p>However, in order to handle transitions between "pending" profiles and "approved" profiles i'd suggest possibly adding in a State Machine to handle the transitions. The AASM gem has been good for me in a recent project. (<a href="http://github.com/rubyist/aasm/tree/master" rel="nofollow noreferrer">http://github.com/rubyist/aasm/tree/master</a>), and I believe Edge Rails has just baked State Machinage right in as well. (<a href="http://github.com/rails/rails/commit/aad5a30bf25d8a3167afd685fc91c99f4f09cc57" rel="nofollow noreferrer">http://github.com/rails/rails/commit/aad5a30bf25d8a3167afd685fc91c99f4f09cc57</a>)</p> <p>Your model could look something like this:</p> <pre><code>class User &lt; AR:B has_one :active_profile has_one :pending_profile include ActiveRecord:: StateMachine state_machine do state :approved state :pending state :rejected event :update_profile_pending do transitions :to =&gt; :pending, :from =&gt; [:approved], :on_transition =&gt; :send_to_admin_queue end event :update_profile_approved do transitions :to =&gt; :approved, :from =&gt; [:pending], :on_transition =&gt; :update_current_profile end event :update_to_rejected do transitions :to =&gt; :rejected, :from =&gt; [:pending] end end def send_to_admin_queue //method to handlesending pending profiles to admin for approval end def update_current_profile //method to handle updated profiles with changes end end </code></pre> <p>You could then call User.update profile pending! or User.update profile approved! to transition between your profile states and use the transition callbacks to handle sending the editing data between your active profile and pending profile.</p> <p>As far as using the nested_attributes_for with your actual form, I don't think it's a hack, I've used it as well to update nested attributes and it'd work fine. In this case though you may not need too since you have 2 profiles (one public, one pending).</p> <p>Just an idea! Thinking out loud here!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload