I\'m having trouble understanding why my app is automatically creating entries in the database when I visit the \"new\" page. The page is supposed to have a form that, when subm
In the controller, the logic to create a Recipe has been written in new method and just a recipe is just initialized in create method. But in the routes the create method has a POST call(form submission with data) and the new method is a GET.
So all you need to do is just change the name of the 'create' method as 'new' and change the name of the 'new' method as 'create' in your controller.
i.e)
def create
@recipe = Recipe.create(params[:recipe])
if @recipe.save
redirect_to recipe_new_path
else
reload_page
end
end
def new
@recipe = Recipe.new
end
This will work.