ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

New and Edit Don't Work #859

Closed laburr27 closed 7 years ago

laburr27 commented 7 years ago

I tried scrubbing the code and comparing to hogwarts, tunr, and got. I expected a new cookbook to be added and redirected to that cookbook's page and edits to be saved and redirected to that cookbook's page to happen. Changes and additions are not saved and I loop back to the new or edit page after clicking the button happened instead. My repo link is: https://github.com/laburr27/cooking-library

class CookbooksController < ApplicationController

  def index
    @cookbooks = Cookbook.all
  end

  def new
    @cookbook = Cookbook.new
  end

  def create
    @cookbook = Cookbook.create(cookbook_params)
    redirect_to cookbooks_path(@cookbook)
  end

  def show
    @cookbook = Cookbook.find(params[:id])
  end

  def edit
    @cookbook = Cookbook.find(params[:id])
  end

  def update
    @cookbook = Cookbook.find(params[:id])
    @cookbook.update(cookbook_params)
    redirect_to cookbook_path(@cookbook)
  end
amaseda commented 7 years ago

Can you change .create to .create! and see if that causes any errors to appear?

laburr27 commented 7 years ago

When I tried to create a new cookbook I got this back:

Started GET "/cookbooks/w3.css" for ::1 at 2017-03-02 10:42:24 -0500 Processing by CookbooksController#show as CSS Parameters: {"id"=>"w3"} Cookbook Load (0.2ms) SELECT "cookbooks".* FROM "cookbooks" WHERE "cookbooks"."id" = $1 LIMIT $2 [["id", 0], ["LIMIT", 1]] Completed 404 Not Found in 2ms (ActiveRecord: 0.2ms)

ActiveRecord::RecordNotFound (Couldn't find Cookbook with 'id'=w3):

app/controllers/cookbooks_controller.rb:17:in `show'

"....bunch of Rendering lines..."

Started GET "/cookbooks/w3.css" for ::1 at 2017-03-02 10:42:24 -0500 Processing by CookbooksController#show as CSS Parameters: {"id"=>"w3"} Cookbook Load (0.2ms) SELECT "cookbooks".* FROM "cookbooks" WHERE "cookbooks"."id" = $1 LIMIT $2 [["id", 0], ["LIMIT", 1]] Completed 404 Not Found in 2ms (ActiveRecord: 0.2ms)

ActiveRecord::RecordNotFound (Couldn't find Cookbook with 'id'=w3):

amaseda commented 7 years ago

Sorry for the delay here. The fact that it's looking for a cookbook with the id w3 is strange. Is that particular string coming from somewhere?

superbuggy commented 7 years ago

this a problem with code incookbooks/new.html.erb. closing for now