您好我正在使用我的应用程序的主动管理员我有一个部分有一个下拉列表,其中填充菜单和配方此页面是在菜单中对食谱进行分组 _menu_recipe.html.erb
<%= semantic_form_for [:admin, @menu_recipe] do |f| %>
<p>
<%= f.collection_select :recipe_id,
Recipe.all,:id,:name,:prompt => true%>
</p>
<p>
<%= f.collection_select :menu_id,
Menu.all,:id,:name,:prompt => true%>
</p>
<%= f.buttons :commit %>
<%end%>
当我尝试捕捉并创建或分组时,它附带一个
Couldn't find Recipe without an ID
错误
我覆盖的活动管理员控制器是
ActiveAdmin.register MenuRecipe do
menu :parent => "Manage Package"
form :partial => "menu_recipe"
controller do
def new
new! do |format|
@menu_recipe = MenuRecipe.new
end
end
def create
create! do |format|
recipe = Recipe.find(params[:recipe_id])
menu = Menu.find(params[:menu_id])
@menu_recipe = @menu.add_recipe(menu.id)
if @menu_recipe.save
redirect_to {admin_menu_recipe_url}
end
end
end
end
end
我似乎无法获得我分组的当前菜单和食谱
答案 0 :(得分:1)
您是否尝试过“检查”params哈希?这部分似乎是错误的:
recipe = Recipe.find(params[:recipe_id])
menu = Menu.find(params[:menu_id])
我本来期望的是:
recipe = Recipe.find(params[:menu_recipe][:recipe_id])
menu = Menu.find(params[:menu_recipe][:menu_id])