Couldn't find Studio without an ID

2019-09-06 02:18发布

问题:

Everything seems to be in the right place but apparently not. Here is a gists with the error information in the gists description.

https://gist.github.com/JRizzle88/7862465

EDIT:

Here is what the trace begins with:

Started GET "/studios/new" for 127.0.0.1 at 2013-12-08 13:52:41 -0600
Processing by StudiosController#new as HTML
Completed 404 Not Found in 1ms

ActiveRecord::RecordNotFound - Couldn't find Studio without an ID:
....
....

回答1:

Change your before_filter in your StudiosController to

before_action :set_studio, except: [:index, :new, :create]

Change your show action to

def show
end

Change your new action to

def new
  @studio = Studio.new
end


回答2:

There is

before_action :set_studio

in your StudiosController. params[:id] seems to be nil here and it can't find Studio with nil id. You should probably add only or except parameter to your before actions.

Another strange thing is

@studio = Studio.new(params[:id])

in StudiosController#new. It should be just

@studio = Studio.new

isn't it?