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 8380703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:31:28+00:00 2026-06-09T16:31:28+00:00

I have a model Position with a field started_at and ended_at , both of

  • 0

I have a model Position with a field started_at and ended_at, both of which are datetime fields. Because the date part of both have to be the same, I have a datetime_select form field for started_at but only a time_select ignore_date: true for ended_at. In the create method I’d like to assign the date values of started_at to ended_at like this:

params[:position]["ended_at(1i)"] = params[:position]["started_at(1i)"]
params[:position]["ended_at(2i)"] = params[:position]["started_at(2i)"]
params[:position]["ended_at(3i)"] = params[:position]["started_at(3i)"]

But this broke my controller specs, because there I assign the values directly:

describe "POST create" do
  describe "with valid params" do
    it "creates a new Position" do
      expect {
        post :create, {:position => valid_attributes}, valid_session
      }.to change(Position, :count).by(1)
    end
  end
end

So I ended up with this, but I’m not sure whether it is a reasonable fix:

if params[:position]["ended_at(1i)"].nil? and not params[:position]["started_at(1i)"].nil? # We have to check this because in the controller specs we assign the params directly (not in this crazy xxx_at(yi) form for dates), so by checking this we know that the data was sent through the form
  params[:position]["ended_at(1i)"] = params[:position]["started_at(1i)"]
  params[:position]["ended_at(2i)"] = params[:position]["started_at(2i)"]
  params[:position]["ended_at(3i)"] = params[:position]["started_at(3i)"]
end

Maybe there’s a better solution? Thanks for your opinions.

  • 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-09T16:31:30+00:00Added an answer on June 9, 2026 at 4:31 pm

    If the controller is expecting the attributes in a specific format, the spec should supply them in that format. Adjust valid_attributes so that it separates the date and time elements in the same way that the form does, and the spec should pass.

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

Sidebar

Related Questions

I have model Foo which has field bar. The bar field should be unique,
I have a Position model for which I have a scope defined: scope :default,
I have model with a location, which itself has a latitude and longitude. What
I have model Article it has field title with some text that may contain
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
In my code I have a Category model which has many subcategories, and the
In a django application I have the following model: class Appointment(models.Model): #some other fields
I have the following two models: class Position(models.Model): position = models.CharField(max_length=100) class UserProfile(models.Model): user
I need to have a model which will behave like a embedded and not-embedded.
I have a problem with Django queryset ordering. My model contains a field named

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.