0
我整合的幾種模式(的想法,問題等)進入控制檯中的一個主題模型,我認爲這樣的事情可能工作:導入字段從一個模型到另一個模型
Question.find_each do |q|
t = Topic.new
t.create(:title=q.title, :description=q.description, :kind=」Question」)
end
但我發現了一個錯誤:
SyntaxError: (irb):24: syntax error, unexpected tIDENTIFIER, expecting ')'
t.create(:title=q.title,:description=q.description,:kind='question')
想知道是否有人曾經嘗試過這樣的模型之間傳輸數據和是否有一個「正確」的方式做到這一點。
[編輯] 這工作:
Question.find_each do |q|
@qt=q.title
@qd=q.description
@q=‘Question’
@ca=q.created_at
@ui=q.user.id
@uvt=q.user_votes_total
Topic.create!({:title => @qt, :description => [@qd], :kind => @q, :created_at=>@ca, :user_id=>@ui, :user_votes_total=>@uvt })
end
謝謝!我發佈了在問題中起作用的最終版本,以便其他人可以在他們的大腦停止工作時找到答案:) –