button_to :action => 'destroy' looks for 'show'

Viewed 50035

This seems incredibly similar to a question I had answered just a few days ago, but the solution then isn't working now.

I'm building a rails app, and I am trying to have a button_to trigger a destroy in a different controller.

the code I have for the button is

<%= button_to "delete", :controller => :meals, 
                           :action => 'destroy',
                           :recipe_id => recipe.id,
                           :method => :post >

when I click the delete button, i get a 'no matches for meals/3' which is the current meal_id.

the destroy in the meals controller looks like this

  def destroy
    @meal = Meal.where("current_user.id => ? AND recipe_id => ?", current_user.id, params[:recipe_id]).first
    @meal.destroy

    respond_to do |format|
      format.html { redirect_to :controller => "user" , :action => "show" }
      format.xml  { head :ok }
    end
  end

it appears as though the button_to is completely ignoring the :action and requesting show which does not exist and shouldn't exist.

2 Answers
Related