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

  • SEARCH
  • Home
  • 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 8500341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:55:07+00:00 2026-06-11T00:55:07+00:00

So in my ClientsController.rb I have a before filter that does the following: Checks

  • 0

So in my ClientsController.rb I have a before filter that does the following:

Checks the current year, and month. If the month is after June, then set the variable vote_year to next year. If it isn’t, then set the vote_year to this year.

Then I am setting the date attribute based on that year, along with the hard month & day of July 1.

Basically, this particular date is on July 1st every year. I want this before filter to set the next date based on whether or not the time that this filter has been run is before or after July 1st.

The code I have is as follows:

before_filter :set_next_vote_date, :only => [:create, :new, :edit, :update]

private

def set_next_vote_date
    client = current_user.clients.find(params[:id])
    today = DateTime.parse(Time.now.to_s)
    year = today.year

    if today.month == 7 && today.day == 1
        vote_year = today.year
    elsif today.month > 6
        vote_year = year + 1
    else
        vote_year = year
    end

    client.next_vote = "#{vote_year}-07-01"         
end

The issue is that there is no error thrown, whenever I do any of those actions on those controllers. But, the next_vote attribute on the client record is not being updated.

What am I missing?

Edit 1:

After I have used update_attribute (without the !), I don’t get an error, but I am not seeing this particular attribute being updated in the log.

Started PUT "/clients/1" for 127.0.0.1 at 2012-09-08 20:09:17 -0500
Processing by ClientsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"J172LuZQc5N=", "client"=>{"name"=>"John F Kennedy", "email"=>"jfk@email.com", "phone"=>"8234698765", "firm_id"=>"1", "topic_ids"=>"2"}, "commit"=>"Update Client", "id"=>"1"}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Client Load (0.1ms)  SELECT "clients".* FROM "clients" WHERE "clients"."user_id" = 1 AND "clients"."id" = ? LIMIT 1  [["id", "1"]]
   (0.1ms)  begin transaction
   (0.0ms)  commit transaction
  CACHE (0.0ms)  SELECT "clients".* FROM "clients" WHERE "clients"."user_id" = 1 AND "clients"."id" = ? LIMIT 1  [["id", "1"]]
   (0.1ms)  begin transaction
  Topic Load (0.6ms)  SELECT "topics".* FROM "topics" WHERE "topics"."id" = ? LIMIT 1  [["id", 2]]
  Topic Load (0.2ms)  SELECT "topics".* FROM "topics" INNER JOIN "clients_topics" ON "topics"."id" = "clients_topics"."topic_id" WHERE "clients_topics"."client_id" = 1
   (0.4ms)  UPDATE "clients" SET "phone" = 823498765, "updated_at" = '2012-09-09 01:09:17.631839' WHERE "clients"."id" = 1
   (1.4ms)  commit transaction
Redirected to http://localhost:3000/clients/1

Note that the next_vote attribute isn’t updated. Granted, I didn’t include that attribute in the edit form partial, but I assumed that this before_filter – if it is being executed, would update the record. But I am not even sure if it is being executed at all.

Edit 2:

Never mind, it seems to be working now. The above log paste was AFTER the edit action, and the before_filter executes before the edit action – DUH! Silly me 🙂

  • 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-06-11T00:55:09+00:00Added an answer on June 11, 2026 at 12:55 am

    It seems you’re not saving the client after changing the attribute.

    Some further suggestions on how to clean up that code a bit:

    before_filter :set_next_vote_date, :only => [:create, :new, :edit, :update]
    
    private
    
    def set_next_vote_date
      client    = current_user.clients.find(params[:id])
      today     = Date.today
      vote_year = today.month > 6 ? today.year + 1 : today.year
    
      client.update_attribute(:next_vote, Date.new(vote_year, 7, 1))
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two methods in C# 3.5 that are identical bar one function call,
I have a core data model with an entity called clients that is made
I have a simple app that has a list of clients in one table
If I have a model named Client and controller that looks like this class
I have tried to add dynamic Zend_Acl assertions to my project following this article:
I have a question about unit testing. Say I have a controller with one
I have a admin namespace i have configured the routes.rb as follows namespace "admin"
lets say I have 2 models like News, Clients. Using paperclip's default options, I
I have a self join through an intersect table in an app I'm working
I have an Employee model, Client model, and an Office model. Devise is controlling

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.