title: Using Devise Current User as default user in User Select box
body: <p>I'm using Devise and Active Admin, and so far there are playing nice together. Instead of using the default Active Admin "AdminUser', I am using my own 'User' model, which is sometimes refered to as 'Author' within my app.</p>
  
  <p>I'm creating an Article form (Create/Update) and I have a User Select Box that is pre-selected if the record is an <em>update</em>, but not if it is a <em>new record</em>. What I want to do is if I am creating a <em>new record</em>, use the Devise' 'current_user'. Since ActiveAdmin is using Formtastic, I found this: <a href="https://github.com/justinfrench/formtastic/wiki/Deprecation-of-%3Aselected-option" rel="nofollow noreferrer">https://github.com/justinfrench/formtastic/wiki/Deprecation-of-%3Aselected-option</a>, which basically explains that might be a feature coming, but that this might be best achieved with a before filter, which is where I am stumped now.</p>
  
  <p>Here is my form view:</p>
  
  <pre><code>&lt;%= semantic_form_for [:admin, @article] do |f| %&gt;
      &lt;%= f.inputs "Details" do %&gt; 
          &lt;%= f.input :title %&gt;
          &lt;%=
              f.input :user, :as =&gt; :select, :label =&gt; 'Author',
              :collection =&gt; User.all, :include_blank =&gt; false,
              :required =&gt; true 
          %&gt;
  
          &lt;%=
              f.input :categories, :as =&gt; :check_boxes, :label =&gt; 'Categories',
              :collection =&gt; Category.all, :include_blank =&gt; 'None',
              :hint =&gt; 'Choose all categories that apply.',
              :required =&gt; false 
          %&gt;
  
          &lt;%= f.input :desc, :label =&gt; 'Description' %&gt;
          &lt;%= f.input :content, :label =&gt; 'Content' %&gt;
      &lt;% end %&gt;
      &lt;%= f.buttons %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I can pre-selct the <em>current_user</em> using jQuery, something like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      $('#article_user_id').val(&lt;%= current_user.id %&gt;);
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>but this overrides the selected user in the 'Edit' view, in which the Author/User has already been assigned... and it also doesn't seem like Rails way...</p>
  
  <p><strong>Edit:</strong>
  I found this:
  <a href="https://stackoverflow.com/questions/6725233/active-admin-customize-only-new-form#answer-6733275">Active Admin: Customize only new form</a></p>
  
  <p>So based on that, in my view I determine if the Article is a new record or not, and if it is, I wrap the javascript so that it gets put on the page for new articles. This way, on article updates, the user is still selected.</p>
  
  <pre><code>&lt;% if controller.action_name == 'new' %&gt;
    &lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      $('#article_user_id').val(&lt;%= current_user.id %&gt;);
    });
    &lt;/script&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Again, I don't think this is the most elegant solution, so if anyone has any comments on a better way (which I'm sure there is), please let me know!</p>