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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:48:13+00:00 2026-05-26T04:48:13+00:00

I am writing a piece of code in my controller that is suposed to

  • 0

I am writing a piece of code in my controller that is suposed to take the data a user inputs in the form of 00:00 and convert that into minutes before sending it to the model. The code I am using is pretty simple, just split the :duration parameter at the colon and multiply hours by 60 and add the minutes to that number. When I submit the for I get an error when it tries to perform split on a nil object. This must mean I am not accessing the parameter correctly but I am confused as to how I would navigate to a deeply nested parameter and cant seem to find any documentation regarding deeply nested parameters.

Here is my model organization:

log_entry >>
has many
workouts >>
has many 
workout_times, which has :duration as an attribute 

This is the code within my log_entries_controller:

def convert_duration
  hours, minutes = params[:log_entry][:workout][:workout_time][:duration].split(":")
  params[:log_entry][:workout][:workout_time][:duration] = (hours.to_i * 60 + minutes.to_i)
end

I have tried all the ways I could think of to write the params part but I cants seem to get it right. I am pretty new to rails/programming so there might be somthing totally obvious I am missing…

EDIT

Here is the log info of parameters past:

Parameters: {
  "commit" => "Save",
  "log_entry" => {
    "date(1i)" => "2011",
    "date(2i)" => "10",
    "date(3i)" => "13",
    "workouts_attributes" => {
      "0" => {
        "time_of_day" => "AM",
        "summary" => "",
        "workout_times_attributes" => {
          "0" => {
            "duration" => "2:00",
            "zone" => "1",
            "_destroy" => "false"
          }
        }
      }
    }
  },
  "authenticity_token"=>"zD6qS6jOSQ3/mRyH7RAgAzWYmwHub0+uBG1sjPVvkEY=",
  "utf8"=>"\342\234\223"
}
  • 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-26T04:48:13+00:00Added an answer on May 26, 2026 at 4:48 am

    You could just assign the parameter you want to your model like so:

    def save
      workout = Workout.new(params[:workout])
      workout.workout_time.duration = convert_duration(workout)  
    end
    

    Then in your convert_duration method do:

    def convert_duration(workout)
      hours, minutes = workout.workout_time.duration.split(":")
      (hours.to_i * 60 + minutes.to_i)
    end
    

    In Ruby the last statement of a method is returned, so this would return your calculated duration back to the save method which will set the duration on the workout_time object for the workout object we created from the parameters passed to the method.

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

Sidebar

Related Questions

I am writing a piece of code in Java that needs to take a
I recently found myself writing a piece of code that executed a Core Data
I am writing a piece of code that transfers selected data on an Excel
I was writing a piece of code that prevents an ushort from overflow/underflow'ing. Before
I'm currently writing a piece of code that does some searches which returns IDisposable
I am writing a piece of code in which i have to convert from
I am writing a piece of Java code that needs to send mail to
i'm currently writing on some piece of code in android 2.1 that is supposed
I am writing a piece of code to read in several GB of data
I'm writing a piece of JS code that returns a result of true if

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.