Open numeroteca opened 5 years ago
Either removing this part of the code: https://github.com/montera34/pageonex/blob/master/app/controllers/threads_controller.rb#L200-L212
# New code
else
# Fetch existing code from database by id and update
code = @thread.codes.find_by_id(id)
if params["topic_deleted_#{index}"] == '1'
code.destroy()
else
unless code_name.empty?
code.update_attributes({code_text: code_name,
color: params["topic_color_#{index}"],
code_description: params["topic_description_#{index}"]})
end
end
or this https://github.com/montera34/pageonex/blob/master/app/controllers/threads_controller.rb#L215-L226
@thread.codes.to_enum.with_index.each do |code,index|
code_name = params["topic_name_#{index}"]
if params["topic_deleted_#{index}"] == '1'
code.destroy()
else #To Do: it should save the new codes created
unless code_name.empty?
code.update_attributes({code_text: code_name,
color: params["topic_color_#{index}"],
code_description: params["topic_description_#{index}"]})
end
end
end
fixes it. It seems there are two codes making a similar/same thing and causes the removal of two codes (not clear to me exactly why). Check #61, maybe relevant related info.
I had forked a thread (http://pageonex.com/numeroteca/partidos-y-elecciones-20d/ to http://pageonex.com/numeroteca/partidos-y-elecciones-20d/) to rework one of the topics. I needed to erase all but one of the topics and I discover these bugs (I'll update this when I find more problems or can give specifics):
Given a thread with 4 topics (A, B, C, D) when the first topic (A) while editing-updating a thread:
I made a test thread to see this behavior. To make it easier the thread I have just one day coded, where the full front page is assigned to a topic that has the name of that very same newspaper.
Original thread:
Thread after removing first topic:
I repeated the process with 5 topics with the same results:
What is causing this problem?
From the topic template (/app/views/threads/_topic_form.html.erb) the delete topic button is formed with the class
.delete_topic
:It is used with this javascript /app/assets/javascripts/topic_form.js script to detect where the click happens and change the id of the topic with a particular index:
When you click in a delete topic button
value="1"
is added:<input id="topic_deleted_0" name="topic_deleted_0" type="hidden" value="1">
so the ruby script /app/controllers/threads_controller.rb is able to detect this and destroy the Topic (called
code
in the project):It seems there is a problem with the selection of these topics ids.