現在、プログラミングで1:nのeditとdestroyを実装しております。
その中で、editとdestroyのコマンドがlinkから上手くページ推移しません。
原因は確定的ではありませんが、以下のようにアソシエーションを記述しております。
company
1class Company < ApplicationRecord 2 has_many :invoices 3 has_one :small 4 has_one :carrier 5 belongs_to :user 6 validates :user_id, presence: true 7end
user
1class User < ApplicationRecord 2 has_one :company 3 # Include default devise modules. Others available are: 4 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 5 devise :database_authenticatable, :registerable, 6 :recoverable, :rememberable, :validatable 7 8end
invoice
1class Invoice < ApplicationRecord 2 belongs_to :company 3end
invoicecontroller
1 before_action :load_company 2 before_action :load_invoice, only: [:edit,:update,:show,:destroy, :report] 3 before_action :authenticate_user! 4 5 def edit 6 end 7 8 def update 9 if @invoice.update(invoice_params) 10 redirect_to company_invoices_path(@company, @invoice) 11 else 12 render 'edit' 13 end 14 end 15 16 def destroy 17 @invoice = @company.invoices.find(params[:id]) 18 @invoice.destroy 19 redirect_to company_invoices_path(@company) 20 end 21
invoiceindex
1 <td><%= invoice.sup_company %></td> 2 <td><%= link_to '編集', edit_company_invoice_path(@company, @invoice), class: "command square_btn" %></td> 3 <td><%= link_to '削除', 4 company_invoice_path(@company,@invoice) , 5 method: :delete, 6 class: 'command square_btn', 7 data: { confirm: '本当に削除しますか?'} %></td> 8 <td><%= link_to 'ダウンロード', report_company_invoice_path(@company, invoice, format: 'pdf'), class: 'command square_btn' %></td>
上記のようにプログラミングしており、URLは
となり、
エラー分は
Started GET "/companies/7/invoices/%23%3CInvoice::ActiveRecord_Relation:0x007f8d975af538%3E/edit" for 192.168.33.1 at 2019-01-26 11:00:58 +0000 Cannot render console from 192.168.33.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by InvoicesController#edit as HTML Parameters: {"company_id"=>"7", "id"=>"#<Invoice::ActiveRecord_Relation:0x007f8d975af538>"} Company Load (2.5ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = ? LIMIT ? [["id", 7], ["LIMIT", 1]] ↳ app/controllers/invoices_controller.rb:8 Invoice Load (0.6ms) SELECT "invoices".* FROM "invoices" WHERE "invoices"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]] ↳ app/controllers/invoices_controller.rb:12 Rendering errors/error_404.html.erb within layouts/application Rendered errors/error_404.html.erb within layouts/application (1.9ms) Rendering layouts/_head.html.erb Rendered layouts/_head.html.erb (155.5ms) Rendering layouts/_header.html.erb Rendered layouts/_header.html.erb (0.4ms) User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]] ↳ app/views/layouts/application.html.erb:17 Rendering layouts/_footer.html.erb Rendered layouts/_footer.html.erb (0.5ms) Completed 404 Not Found in 200ms (Views: 189.5ms | ActiveRecord: 3.3ms)
となります。
おそらくuser_idが影響しているかと思うのですが、どのように記述すれば解決出来ますでしょうか?
よろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。