Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6019573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:29+00:00 2026-05-23T03:26:29+00:00

I have a Log project, each log has a :date, :hours, :description. I am

  • 0

I have a “Log” project, each log has a :date, :hours, :description. I am simply trying to determine how many hours I have worked in a week, but am having trouble determining the proper separation of code. Let me know if any further code is needed. Rails 3.

log.rb

def self.days_in_range(from, to)
  Log.where(:date => (from.to_date)..(to.to_date))
end

index.html.erb

<% content_for :sidebar do %>
<h4> Sidebar Content </h4>
<ul>
  <li>Hours worked this week:
    <%= Log.hours_this_week %> # unsure how to call
  </li>
  <li>Hours worked in total: 
    <%= Log.sum(:hours) %>
  </li>
  <li>Most hours worked in a day:
    <%= Log.maximum(:hours) %>
  </li>
</ul>
<% end %>

logs_helper.rb?

def hours_this_week
  today = Time.now
  day_of_week = today.wday
  sunday = today - day_of_week.days
  days = Log.days_in_range(today, sunday)
  hours = 0

  days.each do |day|
    hours += day.hours
  end

end

[solved] error

Showing /Users/***/Documents/workspace/***/hours_tracker/hours/app/views/logs/index.html.erb where line #33 raised:

undefined method `hours_this_week' for #<LogsController:0x103b66be8>
Extracted source (around line #33):

30:     <h4> Sidebar Content </h4>
31:     <ul>
32:         <li>Hours worked this week:
33:             <%= hours_this_week %>
34:         </li>
35:         <li>Hours worked in total: 
36:             <%= Log.sum(:hours) %>
Rails.root: /Users/***/Documents/workspace/***/hours_tracker/hours

full trace

[updated] new error

error

ArgumentError in Logs#index

Showing /Users/***/Documents/workspace/***/hours_tracker/hours/app/views/logs/index.html.erb where line #33 raised:

wrong number of arguments (0 for 1)
Extracted source (around line #33):

30:     <h4> Sidebar Content </h4>
31:     <ul>
32:         <li>Hours worked this week:
33:             <%= hours_this_week %>
34:         </li>
35:         <li>Hours worked in total: 
36:             <%= Log.sum(:hours) %>
Rails.root: /Users/***/Documents/workspace/***/hours_tracker/hours
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:26:30+00:00Added an answer on May 23, 2026 at 3:26 am

    This is tangential to your question, but I noticed this looking at your hours_this_week method. I could be wrong, but one little thing you may want to look at here is that your hours_this_week method is going to return the collection iterated through in your each statement (i.e. days), not the product of that statement (the new value of hours).

    You could either just add the line:

     hours
    

    to the end of this method, or use inject instead of each:

    # The initial "hours" declaration is no longer necessary,
    # because inject returns its result, rather than the 
    # collection it is iterating through.
    
    days.inject(0) {|hours, day| hours += day.hours }
    

    That line would eliminate the need for your each statement and for explicitly returning hours at the end of your hours_this_week method.

    That said, putting the method in logs_helper.rb and calling it with:

    <%= hours_this_week %>
    

    would be the way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know similar questions have been asked many times befor, but I think this
I have many Javascript or jQuery methods in my ASP.net project. 85%+ is client
I have a project with several dependencies that are in various repositories. Each time
I have posted a question on here previously asking similar advise, but this project
I have a flex .swf and a seperate AIR project which I'm trying to
In a project we are doing we encounter log files of which each line
A project I have been working on for the past year writes out log
We've faced strange problem. We have log on service, that authenticates user, adds auth
I have several log files of events (one event per line). The logs can
I have a log in page where I valid my users and based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.