All threads / how do i resolve this error?

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
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. 🤓
That's got it. Thanks Chris :-D
Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.