active admin destroy action

Go To StackoverFlow.com

0

im working in a project writen in ruby on rails and im currently using the active admin gem for its content manager system of my site im just wondering how active admin is using the delete action im trying to overide it but i my code doesent work, i think we are having a problem in how to get the specific line to be destroy

def destroy


  @menu = Menu.find(params[:menu_recipe][:menu_id])
  @menu_recipe = @menu.menu_recipes.find(params[:id])
  @menu_recipe.remove_recipe
  @menu_recipe.destroy
  redirect_to @reservation, :notice => "recipe destroyed"

      end  

it comes with a error of

undefined method `[]' for nil:NilClass   
2012-04-05 15:14
by Led


0

Probably params[:menu_recipe] is not set. Try putting params[:menu_recipe] ||= {} at the beginning.

But why is it that you're finding through the Menu, anyway? Can't you just do 'MenuRecipe.find(params[:id])'?

2012-04-05 15:18
by tsherif
still the same or i didnt code it right can you please code where to put params[:menu_recipe] ||= {} im new in ruby on rails sorry - Led 2012-04-05 15:25
First, see the edit I just made. If you do need to go through Menu, the line I put should go at the very beginning of the action. Note that you'll also have to be careful before doing Menu.find(params[:menu_recipe][:menu_id]) since if the params[:menu_recipe][:menu_id] is nil, the find will raise an exception - tsherif 2012-04-05 15:33
uhm yea i re-write my code with that and it worked thanks for the help : - Led 2012-04-05 15:59
Ads