わかりました、私は高低を検索し、チュートリアルを読み、ビデオを見ましたが、まだこれでどこにも行きません. ここで同様の質問を読んだことがありますが、質問はより複雑であるか、回答が不足していたので、ここに...
モデル Account と Invoice があります。アカウントを表示する際に、そのアカウントに関連する「新しい請求書を作成」へのリンクを希望します。(後で、実際には、請求書を作成するときにアカウントを選択するための選択フィールドが必要ですが、それは別の難問に任せます)。
ここに私のモデルがあります... アカウント:
class Account < ActiveRecord::Base
attr_accessible :name, :invoice
attr_accessible :name, :invoice
has_many :invoices
end
請求書:
class Invoice < ActiveRecord::Base
belongs_to :account
attr_accessible :amount_pretax, :amount_total, :date_sent, :project, :status, :tax, :account, :account_id
end
今、私の /views/accounts/show.html.erb で
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @account.name %>
</p>
<%= link_to 'New Invoice', new_invoice_path(:account_id=>@account.id) %>
<%= link_to 'Edit', edit_account_path(@account) %> |
<%= link_to 'Back', accounts_path %>
何が起こっているのかというと、新しい請求書のリンクをクリックすると、新しいフォームが表示され、アカウント フィールドにこの奇妙なテキストが入力されます。#<Account:0x10fe16bc0>
フォームを送信すると、次のエラーが表示されます:
ActiveRecord::AssociationTypeMismatch in InvoicesController#create
このステートメントで: これAccount(#2281084000) expected, got String(#2267210740)
と一緒に:
app/controllers/invoices_controller.rb:45:in `new'
app/controllers/invoices_controller.rb:45:in `create'
請求書コントローラの内容は次のとおりです。
def new
@invoice = Invoice.new(:account_id => params[:account_id])
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @invoice }
end
end
def create
@invoice = Invoice.new(params[:invoice])
....
end
上記は私が間違っていると思うところですが、これらの行を何にするかは現時点では私を超えています。私は完全に初心者です。この機能を解決するための助けは、きっと私にたくさんのことを教えてくれます。
御時間ありがとうございます。