El martes, 14 de marzo de 2017 6:12:16 (CET) Chee Chong Hwa escribió:
> Hi Sergio
>
> *Model tasks.rb*
> def initialize_dup(other)
> super
> self.items = other.items.map(&:dup)
> end
>
> *tasks_controller.rb*
>
> # 14/3/17
> conf.actions << :duplicate
> conf.duplicate.link.method = :get
> conf.duplicate.link.position = :after
> conf.duplicate.link.page = true # for new page rendering
> # 14/3/17
>
> Issue : When click the dup link , get
>
> Started POST "/tasks/27/duplicate?_method=post" for ::1 at 2017-03-14
> 13:09:45 +
> 0800
> Processing by TasksController#duplicate as JS
> Parameters: {"id"=>"27"}
> Task Load (0.0ms) SELECT `tasks`.* FROM `tasks` WHERE `tasks`.`id` = 27
> LIMI
> T 1
> Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.0ms)
>
>
> *NoMethodError (undefined method `items' for #<Task:0xa3c6d58>):*
>
> app/models/task.rb:28:in `initialize_dup'
You copied initialize_dup example to your model, you should add that method
only if you have some has_many, has_one or has_and_belongs_to_many
associations which needs to be copied. In the example:
class Bill < ActiveRecord::Base
belongs_to :customer
has_many :items
def initialize_dup(other)
super
self.items = other.items.map(&:dup)
end
end
Bill model has 2 associations, customer is copied to cloned record, but
initialize_dup with self.items = other.items.map(&:dup) line is needed to
clone bill with items.
Another issue is you are getting a JS post request, although you changed link
to use get and page request, I have same config here and it works.
--
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.