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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:16:34+00:00 2026-06-14T22:16:34+00:00

I have 2 objects Weeklyactivity and Weeklyfood . Weeklyactivity has property called food_id .

  • 0

I have 2 objects Weeklyactivity and Weeklyfood. Weeklyactivity has property called food_id. and Weeklyfood has 7 properties called mon, tue, …, sun.

When the user click update weekly food, the action method retrieves daily activity for a given week. It also retrieve all the weeklyfood object, which contains the id of food ate by the user every day of that week.

Weeklyactivities = Weeklyactivity.where(:week => wk)
@weeklyfood = Weeklyfood.New(forms[:weeklyfood])

Now I’d like to iterate over weeklyfood and transfert its data, which contains the id of the food the user ate each day of the week.

I don’t know if this is the right way to do it or even if there is a compact way of writing this code.

Weeklyactivities[:day => 'mon'].food_id = @weeklyfood[:mon]
Weeklyactivities[:day => 'tue'].food_id = @weeklyfood[:tue]
//and son ...

EDIT

I’m getting the following error: “can’t convert Hash into Integer…”

  • 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-14T22:16:35+00:00Added an answer on June 14, 2026 at 10:16 pm

    Not sure I understand the question.

    You have a model Weeklyactivity that has attributes week and day (and others)?

    And according to your code example you have already created rows in the database for all days in a week for Weeklyactivity?

    Now you want to update these rows from a form?

    In that case I have this suggestion:

    @weeklyfood = Weeklyfood.New(forms[:weeklyfood])
    Weeklyactivity.where(:week => wk).each do |weekly_activity|
      if food_id = @weeklyfood[weekly_activity.day.to_sym]
        weekly_activity.food_id = food_id
        unless weekly_activity.save
          # do stuff if not successful
          break
        end
      end
    end
    

    And I think your objects Weeklyactivity and Weeklyfood should be named WeeklyActivity and WeeklyFood with tables respectively weekly_activities and weekly_foods

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

Sidebar

Related Questions

I have objects that has a DateTime property, how can i query for the
If i have objects with properties of type object or objects that are generics,
I have objects A witch has many to many relation ship to object b.
I'll often have objects with properties that use the following pattern: private decimal? _blah;
I have two arrays. In each array I have objects with lots of properties
I have objects where the border color has already been determined. Now I want
Assuming that I have objects similar to this: public class User { public int
I am creating a program where I have objects called hierarchies, which is little
I have objects of a class Choice which are in a list. Choice looks
We have objects that we want to represent in stacks (think of stacking items

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.