Dear Friends,

I have values in table for duties assigned on certain days ranges, e.g
Monday to Tuesday, Wednesday to Friday.

Now I want to show the duties assigned to a person on main screen if the
day of current date is in the range of weekdays assigned to him/her.

I tried the below but no idea.

def show_all_rosters
@dw = Time.now.strftime('%w')
day = Proc.new { |d| Date::DAYNAMES[d] }
@dw1 = day.call(6)
week_days = ["sunday", "monday", "tuesday", "wednesday", "thursday",
"friday", "saturday"]
@ww = week_days[1]
@dd1 = Date.today
@dd2 = Date.tomorrow
@dd3 = Date.today + 1
@theday =Time.now.strftime('%w').downcase
@rosterduties = RosterDuty.find(:all,:conditions=>["lower(duty_day1) =
:theday or lower(duty_day2)=:theday",{:theday => @theday}])
end

Thanks in advance.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fb30265469e76584cffa75e543ae7b77%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colin Law at Mar 13, 2016 at 10:28 am

    On 13 March 2016 at 09:53, Naveed Alam wrote:
    Dear Friends,

    I have values in table for duties assigned on certain days ranges, e.g
    Monday to Tuesday, Wednesday to Friday.

    Now I want to show the duties assigned to a person on main screen if the
    day of current date is in the range of weekdays assigned to him/her.

    I tried the below but no idea.
    In order to write s/w you need to be able to debug your code to see
    why it is not working. An easy way in rails is just to insert code to
    log results to log/development.log, so you could insert into your code
    something like:
    def show_all_rosters
    @dw = Time.now.strftime('%w')
    logger.info "@dw: #{@dw.inspect}"
    day = Proc.new { |d| Date::DAYNAMES[d] }
    logger.info "day: #{day}"

    and so on to see what is not working and fix it. If you don't do that
    then you will never know why the code is not doing what you want.

    After you have done that and either got it working or hit a brick wall
    then come back and ask if there is a better way.

    Colin
    @dw1 = day.call(6)
    week_days = ["sunday", "monday", "tuesday", "wednesday", "thursday",
    "friday", "saturday"]
    @ww = week_days[1]
    @dd1 = Date.today
    @dd2 = Date.tomorrow
    @dd3 = Date.today + 1
    @theday =Time.now.strftime('%w').downcase
    @rosterduties = RosterDuty.find(:all,:conditions=>["lower(duty_day1) =
    :theday or lower(duty_day2)=:theday",{:theday => @theday}])
    end
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv4nQ9oLgdzcB8xv_ExuHJhWmQSu2a9pkTZ%2BUheeuOGnQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 13, 2016 at 10:49 am

    and so on to see what is not working and fix it. If you don't do that
    then you will never know why the code is not doing what you want.

    After you have done that and either got it working or hit a brick wall
    then come back and ask if there is a better way.

    Colin
    Sorry for not making you understand the problem due to my English skill,
    dear all these lines works, but I dont know how to do the following:

    e.g A person is assigned to work from Monday to Wednesday of every month


    and its Tuesday suppose or Monday or Wed, Computer should show that He
    has to do the work today.

    hope u will get it now.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/225f586aedbb0faeb396a33b68851199%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 13, 2016 at 12:08 pm

    On 13 March 2016 at 10:49, Naveed Alam wrote:
    and so on to see what is not working and fix it. If you don't do that
    then you will never know why the code is not doing what you want.

    After you have done that and either got it working or hit a brick wall
    then come back and ask if there is a better way.

    Colin
    Sorry for not making you understand the problem due to my English skill,
    dear all these lines works, but I dont know how to do the following:

    e.g A person is assigned to work from Monday to Wednesday of every month


    and its Tuesday suppose or Monday or Wed, Computer should show that He
    has to do the work today.

    hope u will get it now.
    What are you storing in the database to indicate the working days?
    Tell us the field names and what the fields contain.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuJNzg4Ci0CAcad_43pLSd8wyvaz1YUvRH0N8xrAuzrMQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 13, 2016 at 12:19 pm

    On 13 March 2016 at 12:07, Colin Law wrote:
    On 13 March 2016 at 10:49, Naveed Alam wrote:
    and so on to see what is not working and fix it. If you don't do that
    then you will never know why the code is not doing what you want.

    After you have done that and either got it working or hit a brick wall
    then come back and ask if there is a better way.

    Colin
    Sorry for not making you understand the problem due to my English skill,
    dear all these lines works, but I dont know how to do the following:

    e.g A person is assigned to work from Monday to Wednesday of every month


    and its Tuesday suppose or Monday or Wed, Computer should show that He
    has to do the work today.

    hope u will get it now.
    What are you storing in the database to indicate the working days?
    Tell us the field names and what the fields contain.
    Also how do you record which RosterDuty records relate to a particular person?

    Colin
    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtgni5y%3DphvL0kgUe4avSjTA_bwOfHA-52o4TyYox12oQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 13, 2016 at 2:06 pm

    Also how do you record which RosterDuty records relate to a particular
    person?

    Colin

    My field names are as below:

    id
    Employee_id
    duty_name
    duty_day1 //start day
    duty_day2 //end day
    duty_time

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cb6dfa79c02e68303e0d0a89e9d6afcb%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 13, 2016 at 2:41 pm

    On 13 Mar 2016 14:06, "Naveed Alam" wrote:
    Also how do you record which RosterDuty records relate to a particular
    person?

    Colin

    My field names are as below:

    id
    Employee_id
    duty_name
    duty_day1 //start day
    duty_day2 //end day
    duty_time
    What is saved in duty_dayn? Day as string or as number (0..7)?
    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/rubyonrails-talk/cb6dfa79c02e68303e0d0a89e9d6afcb%40ruby-forum.com
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvAMQKmCf02ehvmRd01NqSpAvVbp7qM1nycRbJ-%3Dnna8A%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 13, 2016 at 2:46 pm

    Colin Law wrote in post #1182172:
    On 13 Mar 2016 14:06, "Naveed Alam" wrote:
    Employee_id
    duty_name
    duty_day1 //start day
    duty_day2 //end day
    duty_time
    What is saved in duty_dayn? Day as string or as number (0..7)?
    Its, Monday, Wednesday etc. as string

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ae5a7e8234df5c411076ac4d4818d1c6%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 13, 2016 at 3:37 pm

    On 13 March 2016 at 14:46, Naveed Alam wrote:
    Colin Law wrote in post #1182172:
    On 13 Mar 2016 14:06, "Naveed Alam" wrote:
    Employee_id
    duty_name
    duty_day1 //start day
    duty_day2 //end day
    duty_time
    What is saved in duty_dayn? Day as string or as number (0..7)?
    Its, Monday, Wednesday etc. as string
    I suggest not doing that, store it as a number and convert when you
    want to display or enter it. That will make querying the database
    much simpler. Then you can get all the duties for an employee for
    today by something like

    today = Time.now.wday
    @employee.roster_duties.where( "duty_day1 >= ? and duty_day2<=?", today, today)

    In fact it may not be quite that simple. It will not cope with a duty
    running from Saturday to Sunday for example, so you may have to extend
    it for that, possibly a where clause something like
    "(duty_day1 <= duty_day2 and duty_day1 <= ? and duty_day2 >= ?) or
    (duty_day1 > duty_day2 and (duty_day1 <= ? or duty_day2 >= ?))",
    today, today, today, today
    I have not tested that so convince yourself it is right before trying
    it. Don't forget to provide automated tests to check all the edge
    conditions.

    Is it something like that you are looking for?

    Colin


    --@employee.roster_duties
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ae5a7e8234df5c411076ac4d4818d1c6%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtLBYeCvvVZ3uRD92KFHLxokyhPXDiG9OMWDwWOgjERNQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 13, 2016 at 5:19 pm

    "(duty_day1 <= duty_day2 and duty_day1 <= ? and duty_day2 >= ?) or
    (duty_day1 > duty_day2 and (duty_day1 <= ? or duty_day2 >= ?))",
    today, today, today, today
    I have not tested that so convince yourself it is right before trying
    it. Don't forget to provide automated tests to check all the edge
    conditions.

    Is it something like that you are looking for?

    Colin
    let me try this then will tell u what happened?

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4f0527188b3cbccac9fa59ba9e362faf%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 14, 2016 at 11:56 am
    Colin
    Dear I changed the Days from names to numbers, in my Add_rosters its
    like below now:

    <%= a.select :duty_day1, [[ "Monday","1"],
    ["Tuesday","2"],["Wednesday","3"],["Thursday","4"],["Friday","5"],["Saturday","6"],["Sunday","0"]],:selected
    => ["Monday","1"] %>


    Change the controller's method to this:

    def show_all_rosters
    @theday =Time.now.strftime('%A').downcase
    @rosterduties = RosterDuty.find(:all,:conditions=>["duty_day1 >= :theday
    and duty_day2 <=:theday",{:theday => @theday}])
    end


    and show_all_rosters view is this:

    <div id="page-yield">
    <% if @rosterduties.present? %>
       <% @rosterduties.each do |r| %>
       <%= r.duty_name %> <br />
       <%= r.duty_place %> <br />
       <%= r.duty_time %> <br />
       <%= r.duty_day1 %> <br />
       <%= r.duty_day2 %> <p>
       <%end%>
      <%end%>
    </div>

    But the result is blank.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20cb5baf7c9bffdc67fd76fa81da8982%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 14, 2016 at 12:27 pm

    On 14 March 2016 at 11:56, Naveed Alam wrote:
    Colin
    Dear I changed the Days from names to numbers, in my Add_rosters its
    like below now:

    <%= a.select :duty_day1, [[ "Monday","1"],
    ["Tuesday","2"],["Wednesday","3"],["Thursday","4"],["Friday","5"],["Saturday","6"],["Sunday","0"]],:selected
    => ["Monday","1"] %>


    Change the controller's method to this:

    def show_all_rosters
    @theday =Time.now.strftime('%A').downcase
    Have you tried inserting logger.info lines as I suggested previously
    to see what is happening. What is the value of @theday
    @rosterduties = RosterDuty.find(:all,:conditions=>["duty_day1 >= :theday
    and duty_day2 <=:theday",{:theday => @theday}])
    Why are you not using Roster.Duty.where(...)?

    Colin
    end


    and show_all_rosters view is this:

    <div id="page-yield">
    <% if @rosterduties.present? %>
    <% @rosterduties.each do |r| %>
    <%= r.duty_name %> <br />
    <%= r.duty_place %> <br />
    <%= r.duty_time %> <br />
    <%= r.duty_day1 %> <br />
    <%= r.duty_day2 %> <p>
    <%end%>
    <%end%>
    </div>

    But the result is blank.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20cb5baf7c9bffdc67fd76fa81da8982%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtf8du42UTiqBBuXwtKzux63q_gX5m-EFH4UQy7VDdfDA%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Naveed Alam at Mar 16, 2016 at 8:05 am

    Why are you not using Roster.Duty.where(...)?

    Colin
    Thanks dear it worked, I just changed

    @theday =Time.now.strftime('%A').downcase

    to this
    @theday =Time.now.strftime('%w')

    and the condition line as you suggested to this

    @rosterduties = RosterDuty.find(:all, :conditions => ["(duty_day1 <=
    duty_day2 and duty_day1 <= ? and duty_day2 >= ?) or (duty_day1 >
    duty_day2 and (duty_day1 <= ? or duty_day2 >= ?))",@theday, @theday,
    @theday, @theday])

    thanks again.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9bd5c6dbfe143deb3998d959c3f0859d%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Mar 16, 2016 at 8:33 am

    On 16 March 2016 at 08:05, Naveed Alam wrote:

    Why are you not using Roster.Duty.where(...)?

    Colin
    Thanks dear it worked, I just changed

    @theday =Time.now.strftime('%A').downcase

    to this
    @theday =Time.now.strftime('%w')
    Does Time.now.wday not work?

    One thing to watch out for is time zones. If the user and the rails
    server are both set to the same timezone then you should be ok, but if
    they are using different timezones then time.now (which runs on the
    server) will not show the users time, so the time (for the user) at
    which the current day changes from, for example, sunday to monday,
    will not be midnight.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu1CCS6npjV7MyLdVaFKx%3Duwg1ysQRNerFcq3_TFohyJg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 13, '16 at 9:53a
activeMar 16, '16 at 8:33a
posts14
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Naveed Alam: 7 posts Colin Law: 7 posts

People

Translate

site design / logo © 2022 Grokbase