Rails 重复记录未呈现新记录
我想要的只是复制现有记录。它应该使用填充的数据呈现新表单,并让我“创建”这个新记录。
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
all I want is duplicate an existing record. It should render new form with populated data and let me 'Create' this new record.
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
My Model
def clone
self.dup()
self.slug = nil
end
I get this error:
No route matches {:action=>"show", :controller=>"agreements", :format=>nil, :id=>#<Agreement id: 1, date: "2011-12-18",...`
Routes
resources :agreements do
member do
post 'approve'
get 'clone', :controller => 'agreements', :action => 'clone'
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的克隆方法应该是:
和控制器:
ps: 为什么你在你的路由中指定控制器和操作。这是默认的情况,还是我遗漏了什么?
I think your clone method should be:
And the controller:
ps: Why do you specify the controller and action in your routes. It's what the default would be, or am I missing something?