Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

chloe-reimer's Profile

GitHub User: chloe-reimer

Comments by

Avatar

I forgot to include @entry.save, which became problematic in Part 2... modified create method below.

ruby
    def create
        @entry = Entry.new( entry_params )
        @entry.save
        respond_with @entry
    end
Avatar

Since the given EntriesController doesn't use strong parameters, I'd get 500 errors when attempting to create/update entries in the console. I revised EntriesController to the below version, which hasn't thrown any problems my way so far.

ruby
class EntriesController < ApplicationController
    respond_to :json

    def index
        respond_with Entry.all
    end

    def show
        respond_with Entry.find(params[:id])
    end

    def create
        @entry = Entry.new( entry_params )
        respond_with @entry
    end

    def update
        @entry = Entry.find(params[:id])
        respond_with @entry.update( entry_params )
    end

    def destroy
        respond_with Entry.destroy(params[:id])
    end

    private

    def entry_params
        params.require(:entry).permit(:name,:winner)
    end
end