Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:15:14+00:00 2026-06-01T14:15:14+00:00

I’m using Devise and Active Admin, and so far there are playing nice together.

  • 0

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.

I’m creating an Article form (Create/Update) and I have a User Select Box that is pre-selected if the record is an update, but not if it is a new record. What I want to do is if I am creating a new record, use the Devise’ ‘current_user’. Since ActiveAdmin is using Formtastic, I found this: https://github.com/justinfrench/formtastic/wiki/Deprecation-of-%3Aselected-option, 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.

Here is my form view:

<%= semantic_form_for [:admin, @article] do |f| %>
    <%= f.inputs "Details" do %> 
        <%= f.input :title %>
        <%=
            f.input :user, :as => :select, :label => 'Author',
            :collection => User.all, :include_blank => false,
            :required => true 
        %>

        <%=
            f.input :categories, :as => :check_boxes, :label => 'Categories',
            :collection => Category.all, :include_blank => 'None',
            :hint => 'Choose all categories that apply.',
            :required => false 
        %>

        <%= f.input :desc, :label => 'Description' %>
        <%= f.input :content, :label => 'Content' %>
    <% end %>
    <%= f.buttons %>
<% end %>

I can pre-selct the current_user using jQuery, something like this:

<script type="text/javascript">
  $(document).ready(function() {
    $('#article_user_id').val(<%= current_user.id %>);
  });
</script>

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…

Edit:
I found this:
Active Admin: Customize only new form

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.

<% if controller.action_name == 'new' %>
  <script type="text/javascript">
  $(document).ready(function() {
    $('#article_user_id').val(<%= current_user.id %>);
  });
  </script>
<% end %>

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:15:15+00:00Added an answer on June 1, 2026 at 2:15 pm

    Use a before_filter in your controller…

    controller do
      before_filter :assign_user, :only => :new
    
      private
    
      def assign_user
        resource.user = current_user
      end
    end
    

    This way, when your form is rendered, @article will already have the user id populated via the call to the resource method (which references @article in your case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.