2011-04-02 77 views
0

我只能在查詢的幫助下將所有保存在「第一個」表中的數據傳遞給「first_archives」表。我在'destroy'下使用「first」控制器中的查詢,以便從「first」中選擇id並插入到歸檔表中。 代碼如下:帶導軌的MySQL

class FirstsController < ApplicationController 
def destroy 
    @first = First.find(params[:id]) 
    if @first.destroy 
     cd = First_archive.new :first_id =>"First.find :all, :conditions => { :id => @id }" 
     cd.save 

    respond_to do |format| 
     format.html { redirect_to(firsts_url) } 
     format.xml { head :ok } 
    end 
    end 

請幫助疑惑兩兩件事:
*所使用的語法是正確的。
*我們必須寫在first_archive表中。
謝謝

回答

0

我已經解決了它:

x = X.find(params[:id]) 
archive = XArchive.new 
archive.x_id = X.id 
archive.x_name = x.x_name 
archive.start_date = x.start_date 
archive.end_date = x.end_date 
archive.created_at = x.created_at 
archive.updated_at = x.updated_at 
archive.save 
x.destroy 

照顧