开发者

MySQL with rails

I have to pass all the data saved in "first" table to "first_archives" table with the help of queries only. I used the query in the controller of "first" under 'destroy' such 开发者_如何学编程that it is selecting the id from "first" and inserting into archive table. The code as follows:

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

Please help for the doubts for two things:

* Is the syntax used is correct.

* What we have to write in first_archive table.

Thank you


I have solved it by:

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

take care

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜