noosfero | Migration to article invalid in Suggest Article (!1232)
Rodrigo Souto
gitlab at mg.gitlab.com
Mon Jun 12 18:01:38 BRT 2017
Rodrigo Souto started a new discussion on db/migrate/20170607131552_update_suggest_article_data.rb:
> +class UpdateSuggestArticleData < ActiveRecord::Migration
> + def change
> + say_with_time "Updating suggest article datas..." do
> + Task.all.each do |task|
> + if task.type == "SuggestArticle" && task.data[:article].nil?
> + data = task.data
> + article = []
> + article = {:name => data[:article_name],
> + :source_name => data[:source_name],
> + :source => data[:source],
> + :abstract => data[:article_abstract],
> + :body => data[:article_body]
> + }
> + task.data = {:article => article}
By setting the whole `task.data` you are overwritting every other configuration there might be on the hash. See this example:
```
# CORRECT
0> data = {a: 1, b: 2, c: 3}
=> {:a=>1, :b=>2, :c=>3}
0> data[:a] = 4
0> p data
=> {:a=>4, :b=>2, :c=>3}
# WRONG
0> data = {a: 1, b: 2, c: 3}
=> {:a=>1, :b=>2, :c=>3}
0> data = {a: 4}
0> p data
=> {:a=>4}
```
So intead of `task.data = {:article => article}` you should use `task.data[:article] = article`.
---
Reply to this email directly or view it on GitLab: https://gitlab.com/noosfero/noosfero/merge_requests/1232#note_32140479
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170612/1f55a183/attachment.html>
More information about the Noosfero-dev
mailing list