Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue #2 #26

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Fixed Issue #2 #26

wants to merge 6 commits into from

Conversation

bachtsui
Copy link

@bachtsui bachtsui commented Feb 5, 2016

This branch will

fix #2

Commits show the process of how the bug was fixed.

</li>
<% end %>
</ul>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you unindented everything by one space here....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up, spacing should be fixed now.

@bachtsui
Copy link
Author

bachtsui commented Feb 5, 2016

For archives_sidebar.rb
It looked like when you used Modulus 12, month = (entry.month.to_i%12) +1, you were getting a plus one error for Name of Month being displayed.

But taking amount the +1, will produce an error on line 37, month: month-1, because 0-1= -1 and -1 is not a month.

Strangely enough taking out the +1 on line 33 and taking out -1 on line 37, still throws an error and will not display your archive bar. To be honest, I'm not sure why it throws an error as that should work.

Modulus 13 resolves the problems of getting a negative month though, also makes it impossible to get 0 as a result. Having month be 0 might throw an error.

For _content.html.erb
You had to take out the +1 for month because it increments your month hyperlinks by one too much.

</ul>
</div>
<% end %>
<h3 class="sidebar-title"><%= sidebar.title %></h3>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing a class name in this PR? Please defend.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, that was a fix for Issue 1, I reverted it back to underscores. This commit should only fix Issue 2 and only Issue 2.

@tgaff
Copy link
Member

tgaff commented Feb 5, 2016

Exceedingly close, but again, why do you need % at all? Is it necessary?

@bachtsui
Copy link
Author

bachtsui commented Feb 5, 2016

Removing modulous completely and taking out the plus and minus 1 seems to produce the correct results. However, I'm still uncertain as to why at the moment.

It has to do with how does "(entry.month.to_i) " increment itself. If it loops over 1-12, then I think I have the answer. Going to see if I can find a way to check.

@bachtsui
Copy link
Author

bachtsui commented Feb 5, 2016

I believe "(entry.month.to_i)" only loops through the numbers 1-12. Somewhere in the code, every month has the correct corresponding number to it (January => 1, February => 2 ... December =>12). I entry.month is a string ("1", "2"..."12"), so it gets converted to an integer.

"name: I18n.l(Date.new(year, month), format: '%B %Y')" at this point when you put in the right integer I think I18n.l will put in the right month that corresponds to the integer.

@nathanallen
Copy link
Contributor

Correct.

@@ -30,11 +30,11 @@ def parse_request(_contents, _params)
article_counts = Content.find_by_sql(["select count(*) as count, #{date_func} from contents where type='Article' and published = ? and published_at < ? group by year,month order by year desc,month desc limit ? ", true, Time.now, count.to_i])

@archives = article_counts.map do |entry|
month = (entry.month.to_i%12)+1
month = (entry.month.to_i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please removing trailing whitespace.
  • Parentheses are now unnecessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, thanks for the heads up. Didn't even notice the trailing white space.

I think I understand the original logic to it now as well. The original code add +1 to the end of %12 to not get 0. It seems like line 37 month: month-1, was a bit of a red herring. But the point is that you don't even need %12 in the first place and can get rid of these +1 and -1 entirely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nathanallen
Copy link
Contributor

Nice work! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Top Month Always Empty (Archive Sidebar)
3 participants