You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ActiveAdmin自定义页面中CKEditor表单主题字段不显示求助

Hey there, let's get that missing subject field showing up in your ActiveAdmin custom page! I see a couple of small issues in your code that are causing the problem, plus we need to make sure the form submission route is properly set up. Here's how to fix it:

First, let's adjust your code to get the subject field visible and the form working correctly

Option 1: Fixing the semantic_form_for approach

ActiveAdmin.register_page "Mail", namespace: :lku do
  # Register the POST route for sending mail (this was missing before)
  collection_action :send_mail, method: :post do
    # Add your Mailjet sending logic here using params[:subject] and params[:text]
    # Example:
    # Mailjet::Send.create(messages: [{Subject: params[:subject], TextPart: params[:text], ...}])
    redirect_to lku_mail_path, notice: "Mail queued successfully!"
  end

  content do
    panel 'Write mail' do
      # Use the ActiveAdmin form builder explicitly for consistent styling
      semantic_form_for :mail, url: lku_send_mail_path, method: :post, builder: ActiveAdmin::FormBuilder do |f|
        f.inputs "Mail Details" do
          # Explicitly set label and ensure input_html is properly formatted
          f.input :subject, input_html: { name: 'subject' }, label: "Email Subject"
          f.input :text, as: :ckeditor, input_html: { name: 'text' }, label: "Email Content"
        end
        # Add submit button with actions
        f.actions do
          f.action :submit, label: "Send Mail"
        end
      end
    end
  end
end

Option 2: Using form_tag (simpler for model-less forms)
If you prefer a more straightforward approach for model-less forms, form_tag works great with ActiveAdmin's helpers:

ActiveAdmin.register_page "Mail", namespace: :lku do
  collection_action :send_mail, method: :post do
    # Your Mailjet logic here
    redirect_to lku_mail_path, notice: "Mail sent!"
  end

  content do
    panel 'Write mail' do
      form_tag lku_send_mail_path, method: :post do
        inputs "Mail Details" do
          input :subject, type: :text, name: 'subject', label: "Email Subject"
          input :text, as: :ckeditor, name: 'text', label: "Email Content"
        end
        actions do
          submit_button "Send Mail"
        end
      end
    end
  end
end

Why your original code wasn't showing the subject field

  1. Missing route definition: Your original def send_mail didn't register a proper route for the form submission. Using collection_action tells ActiveAdmin to create the correct POST route.
  2. Model-less form handling: semantic_form_for expects a model by default. When you use a symbol like :mail without a corresponding model, it might skip rendering fields that don't map to a known attribute. Explicitly using the ActiveAdmin form builder or switching to form_tag fixes this.
  3. Input block structure: Splitting inputs into separate f.inputs blocks isn't inherently wrong, but combining them under a single block ensures consistent rendering, and adding explicit labels helps with visibility.

After making these changes, both the subject input and CKEditor field should show up, along with a working submit button.

内容的提问来源于stack exchange,提问作者user9134227

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:17:15