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
- Missing route definition: Your original
def send_maildidn't register a proper route for the form submission. Usingcollection_actiontells ActiveAdmin to create the correct POST route. - Model-less form handling:
semantic_form_forexpects a model by default. When you use a symbol like:mailwithout a corresponding model, it might skip rendering fields that don't map to a known attribute. Explicitly using the ActiveAdmin form builder or switching toform_tagfixes this. - Input block structure: Splitting inputs into separate
f.inputsblocks 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
相关产品推荐
相关产品推荐

