我想要的只是复制现有记录。它应该使用填充数据呈现新表单,并让我“创建”这条新记录。
def clone
@agreement = Agreement.find_by_slug!(params[:id])
@agreement.clone
respond_to do |format|
format.html { render action: "new", notice: 'Agreement was successfully cloned.' }
end
end
我的模特
def clone
self.dup()
self.slug = nil
end
我收到此错误:
No route matches {:action=>"show", :controller=>"agreements", :format=>nil, :id=>#<Agreement id: 1, date: "2011-12-18",...`
路线
resources :agreements do
member do
post 'approve'
get 'clone', :controller => 'agreements', :action => 'clone'
end
end
答案 0 :(得分:2)
我认为你的克隆方法应该是:
def clone
clone = self.dup()
clone.slug = nil
clone
end
控制器:
agreement = Agreement.find_by_slug!(params[:id])
@agreement = agreement.clone
ps:为什么要在路线中指定控制器和操作。这是默认的,还是我错过了什么?