El sábado, 11 de marzo de 2017 4:29:10 (CET) Chee Chong Hwa escribió:
> HI Sergio
> 
> Trace from rails server
> Started GET "/tasks/26/clone?adapter=_list_inline_adapter" for ::1 at
> 2017-03-11
>  11:26:59 +0800
>   ActiveRecord::SchemaMigration Load (0.0ms)  SELECT `schema_migrations`.*
> FROM
> `schema_migrations`
> Processing by TasksController#clone as JS
>   Parameters: {"adapter"=>"_list_inline_adapter", "id"=>"26"}
>   Task Load (15.6ms)  SELECT  `tasks`.* FROM `tasks` WHERE `tasks`.`id` =
> 26 LIM
> IT 1
>    (0.0ms)  BEGIN
>   Task Exists (0.0ms)  SELECT  1 AS one FROM `tasks` WHERE `tasks`.`task` =
> BINA
> RY 'Activate Authentication' LIMIT 1
>    (0.0ms)  ROLLBACK
> No template found for TasksController#clone, rendering head :no_content
> Completed 204 No Content in 10278ms (ActiveRecord: 15.6ms)

Task is loaded, then there is a query looking for tasks.task = 'Activate 
Authentication'. I guess you have some uniqueness validation on task column.

Also, you have no view for clone action, you should add one to render new 
task, or display errors, for example using flash. Or you can redirect to index 
action. You should check if save worked, if failed then you can check 
new_task.errors for validation errors:

if new_task.save
  render or redirect
else
  flash.now[:error] = ...
  render ...
end

If you are going to redirect when saving new task fails, you should use 
flash[:error] instead of flash.now

Another thing, you shouldn't use GET requests for actions which save to 
database, I would use PUT (change route to put and add :method => :put to 
action_link). If action renders a js view, add :position => false to 
action_link, default :position is :replace which expects action to return html 
to display.

Anyway, you can use active_scaffold_duplicate gem, it adds :duplicate action, 
which can be setup to create new record on click, or open a form prefilled with 
cloned record. If you have uniqueness validation, you need to generate new 
unique value for column or open form instead of duplicating on click.

> 
> On Saturday, 11 March 2017 11:24:45 UTC+8, Chee Chong Hwa wrote:
> > Hi Segio
> > 
> > Tasks Controller
> > 
> >  conf.action_links.add 'clone', :label => 'Clone', :page => false, :type
> > 
> > => :member
> > Nb. This displays corretly on per record basis
> > 
> > def clone
> > 
> >  old_task = Task.find(params[:id])
> >  new_task = old_task.dup
> >  new_task.save
> > 
> > end
> > 
> > Routes.rb
> > 
> >   resources :tasks, concerns: :active_scaffold
> > 
> > resources :tasks do
> > 
> >     member do
> >     
> >      get 'clone' =>"tasks#clone"
> >     
> >     end
> >     as_routes
> >   
> >   end
> > 
> > Issue: When I click clone... something is happening but the duplicate
> > record is not being save or perhaps not duplicated at all
> > 
> > BTW, I got the idea from
> > http://stackoverflow.com/questions/60033/what-is-the-easiest-way-to-duplic
> > ate-an-activerecord-record
> > 
> > Q. What have I done wrong ?


-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/activescaffold.
For more options, visit https://groups.google.com/d/optout.

Reply via email to