4

I have a custom form for rails activeadmin, but for some reason the action of the form is throwing error:

undefined method `posts_path' for #<#<Class:0x007f63cad3e5c0>:0x007f63bcc4e2e0>

Heres my admin/post.rb

ActiveAdmin.register Post do


  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # permit_params :list, :of, :attributes, :on, :model
  #
  # or
  #
  # permit_params do
  #   permitted = [:permitted, :attributes]
  #   permitted << :other if resource.something?
  #   permitted
  # end

  form :partial => 'form'

end

My partial file _form.html.erb

<%= form_tag(resource, method: "post", multipart: true, class: 'formtastic post') do %>
<fieldset class="inputs">
    <ol>
        <li id="post_title_input" class="string input optional stringish">
            <%= label_tag('post_title', "Title") %>
            <%= text_field(:post, :title) %></li>
        <li id="post_description_input" class="text input optional">
            <%= label_tag('description', "Description") %>
            <%= text_area_tag(:description) %></li>
        <li id="post_file_upload_input" class="text input optional">
            <%= label_tag('file', "Upload Image") %>
            <%= file_field_tag :file %></li>
        <li id="post_file_upload_input" class="text input optional">
            <%= label_tag('file', "Select Theme:") %>
            <%= collection_select(:post, :category_id, Category.all, :id, :title, prompt: true) %></li>
    </ol>
</fieldset>

<fieldset class="actions">
    <ol>
        <li id="post_submit_action" class="action input_action ">
            <%= submit_tag("Create Post") %>
        </li>
        <li class="cancel">
            <a href="/admin/posts">Cancel</a>
        </li>
    </ol>
</fieldset>
<% end %>
1
  • did you manage to solve this one? Commented Apr 23, 2015 at 10:18

2 Answers 2

1

Well, form builder is trying to find posts_path, whereas posts are under admin scope

Try

= active_admin_form_for [:admin, resource] do |f|

Also

= semantic_form_for [:admin, resource] do |f|

works as well

Sign up to request clarification or add additional context in comments.

Comments

0

My workaround:

<% url = resource.new_record? ? admin_posts_path : admin_post_path(resource) %>
<%= form_tag url do |f| %>
  <%= text_field(:post, :title) %>
<% end %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.