问题
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
回答1:
I think your clone method should be:
def clone
clone = self.dup()
clone.slug = nil
clone
end
And the controller:
agreement = Agreement.find_by_slug!(params[:id])
@agreement = agreement.clone
ps: Why do you specify the controller and action in your routes. It's what the default would be, or am I missing something?
来源:https://stackoverflow.com/questions/8555488/rails-duplicate-record-not-rendering-new