Ask A Question

Notifications

You’re not receiving notifications from this thread.

how do i resolve this error?

Alan Morley asked in Ruby
undefined local variable or method `recipe_params' for #<RecipesController:0x00007ffa3c046490> Did you mean? recipe_path

 def create

@recipe = Recipe.new(recipe_params)

if @recipe.save
redirect_to root_path
class RecipesController < ApplicationController
  
  def index
  end
  
  def new
    @recipe = Recipe.new
  end
  
  def create
    @recipe = Recipe.new(recipe_params)
    
    if @recipe.save
      redirect_to root_path
    else 
      render 'new'
    end
  end
  
    private
  
  def book_params
    params.require(:recipe).permit(:title, :description, :rating, :author)
  end
  
end
Reply
Hey Alan! 

Change your "book_params" method at the bottom of the controller to "recipe_params" and you should be good. Looks like just a copy-paste typo you missed. 🤓
Reply
That's got it. Thanks Chris :-D
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.