我在Rails應用程序的工作與嵌套表格等..每一件事情,直到我添加了一個按鈕,嘗試新線項目添加到形式運作良好。該佈局是一種用戶可以創建一個GeneralReport,一旦在GeneralReport裏面,他們可以添加一個Report Entry(GenRepEnt),但是當我添加按鈕時,我得到以下錯誤。的ActiveRecord :: RecordNotFound問題的Rails 4
的ActiveRecord :: RecordNotFound在 GeneralReports :: GenRepEntsController#新
編輯#1的功能在控制檯和劑量的作品,結果填充在本地應用..
有問題的鏈接?是
<%= link_to "New Report Entry", new_general_report_gen_rep_ent_path(@gen_rep_ents) %>
的控制器GenRepEnts如下:
class GeneralReports::GenRepEntsController < ApplicationController
before_action :set_gen_rep_ent, only: [:show, :edit, :update, :destroy]
# GET /gen_rep_ents
# GET /gen_rep_ents.json
def index
@gen_rep_ents = GenRepEnt.all
end
# GET /gen_rep_ents/1
# GET /gen_rep_ents/1.json
def show
end
# GET /gen_rep_ents/new
def new
@general_report = GeneralReport.find(params[:general_report_id])
@gen_rep_ent = GenRepEnt.new
end
# GET /gen_rep_ents/1/edit
def edit
end
# POST /gen_rep_ents
# POST /gen_rep_ents.json
def create
@general_report = GeneralReport.find(params[:general_report_id])
@gen_rep_ent = GenRepEnt.new(gen_rep_ent_params)
@gen_rep_ent.general_report_id = @general_report.id
respond_to do |format|
if @gen_rep_ent.save
format.html { redirect_to @general_report, notice: 'General Report Entry was successfully created.' }
format.json { render :show, status: :created, location: @general_report}
else
format.html { render :new }
format.json { render json: @general_report.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /gen_rep_ents/1
# PATCH/PUT /gen_rep_ents/1.json
def update
respond_to do |format|
if @gen_rep_ent.update(gen_rep_ent_params)
format.html { redirect_to @gen_rep_ent, notice: 'General Report Entry was successfully updated.' }
format.json { render :show, status: :ok, location: @gen_rep_ent }
else
format.html { render :edit }
format.json { render json: @gen_rep_ent.errors, status: :unprocessable_entity }
end
end
end
# DELETE /gen_rep_ents/1
# DELETE /gen_rep_ents/1.json
def destroy
@gen_rep_ent.destroy
respond_to do |format|
format.html { redirect_to gen_rep_ents_url, notice: 'General Report Entry was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_gen_rep_ent
@gen_rep_ent = GenRepEnt.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def gen_rep_ent_params
params.require(:gen_rep_ent).permit(:time, :report, :general_report)
end
end
我GeneralReport型號:
class GeneralReport < ActiveRecord::Base
# Adds Model Relationships
## GeneralReport -> GenRepEnt
has_many :gen_rep_ents, dependent: :destroy
end
我GenRepEnt型號:
class GenRepEnt < ActiveRecord::Base
belongs_to :general_report
end
這是路線。 rb文件:
Rails.application.routes.draw do
resources :general_reports do
resources :gen_rep_ents, except: [:index], controller: 'general_reports/gen_rep_ents'
end
end
而只是櫃面這裏是嵌套的路線
general_report_gen_rep_ents POST /general_reports/:general_report_id/gen_rep_ents(.:format) general_reports/gen_rep_ents#create
new_general_report_gen_rep_ent GET /general_reports/:general_report_id/gen_rep_ents/new(.:format) general_reports/gen_rep_ents#new
edit_general_report_gen_rep_ent GET /general_reports/:general_report_id/gen_rep_ents/:id/edit(.:format) general_reports/gen_rep_ents#edit
general_report_gen_rep_ent GET /general_reports/:general_report_id/gen_rep_ents/:id(.:format) general_reports/gen_rep_ents#show
PATCH /general_reports/:general_report_id/gen_rep_ents/:id(.:format) general_reports/gen_rep_ents#update
PUT /general_reports/:general_report_id/gen_rep_ents/:id(.:format) general_reports/gen_rep_ents#update
DELETE /general_reports/:general_report_id/gen_rep_ents/:id(.:format) general_reports/gen_rep_ents#destroy
我道歉,如果這是一個簡單的問題耙/路線,但它可能只是我還需要第二雙眼睛就可以了因爲我一直在把它放在一些長時間..所有的幫助,非常感謝!讓我知道是否需要更多信息。提供
編輯#2
服務器日誌:
Started GET "/general_reports/%23%3CGenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30%3E/gen_rep_ents/new" for ::1 at 2015-09-10 02:01:04 -0600
ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by GeneralReports::GenRepEntsController#new as HTML
Parameters: {"general_report_id"=>"#<GenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30>"}
GeneralReport Load (0.3ms) SELECT "general_reports".* FROM "general_reports" WHERE "general_reports"."id" = $1 LIMIT 1 [["id", 0]]
Completed 404 Not Found in 22ms (ActiveRecord: 2.9ms)
ActiveRecord::RecordNotFound (Couldn't find GeneralReport with 'id'=#<GenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30>):
app/controllers/general_reports/gen_rep_ents_controller.rb:17:in `new'
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (10.4ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.5ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (67.1ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.8ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.8ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.7ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.8ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (46.0ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.6ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (1.3ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (108.5ms)
Started GET "/general_reports/%23%3CGenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30%3E/gen_rep_ents/new" for ::1 at 2015-09-10 02:01:04 -0600
Processing by GeneralReports::GenRepEntsController#new as HTML
Parameters: {"general_report_id"=>"#<GenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30>"}
GeneralReport Load (0.2ms) SELECT "general_reports".* FROM "general_reports" WHERE "general_reports"."id" = $1 LIMIT 1 [["id", 0]]
Completed 404 Not Found in 2ms (ActiveRecord: 0.2ms)
ActiveRecord::RecordNotFound (Couldn't find GeneralReport with 'id'=#<GenRepEnt::ActiveRecord_Associations_CollectionProxy:0x007fa547608f30>):
app/controllers/general_reports/gen_rep_ents_controller.rb:17:in `new'
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.0ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.4ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.1ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (54.8ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.5ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.6ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.7ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (43.2ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.7ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.9ms)
Rendered /Users/TaurenLTD1/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (96.0ms)
請縮短你的代碼,所以你需要幫助的可以快速查看有關問題的releavant東西的人:放只有使用的路由,只有另一端控制器 – Meier
中的相關操作,查看日誌或控制檯,並複製導致錯誤的參數散列。 – Meier
完成。我已經削減了很多脂肪..我習慣於被要求更多,所以我想我會提供所有我想到的..我的道歉使眼睛流血。 –