我有一个rails activeadmin的自定义表单,但由于某种原因,表单的操作引发了错误:
undefined method `posts_path' for #<#<Class:0x007f63cad3e5c0>:0x007f63bcc4e2e0>
继承人我的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
我的部分文件_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 %>
答案 0 :(得分:1)
好吧,表单构建器正在尝试查找posts_path
,而帖子位于admin
范围
尝试
= active_admin_form_for [:admin, resource] do |f|
另外
= semantic_form_for [:admin, resource] do |f|
也适用
答案 1 :(得分:0)
我的解决方法:
<% url = resource.new_record? ? admin_posts_path : admin_post_path(resource) %>
<%= form_tag url do |f| %>
<%= text_field(:post, :title) %>
<% end %>