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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:26:58+00:00 2026-05-19T00:26:58+00:00

I have a problem concerning the build method in rails 3. I want to

  • 0

I have a problem concerning the build method in rails 3. I want to create a Todo with foreignkeys of project and group.

The associations look like

Group has_many projects and todos

Project has_many todos, belongs_to group

Todo belongs_to 1 project and 1 group

My routes
resources :groups do
        resources :projects do
            resources :todos
        end
end

work perfect.

The form also works perfectly with:

<%= form_for [@group, @project, @todo] do |f| %>

My problem is now the CREATE and UPDATE Method in the Todo-Controller.

   def create
        @group   = Group.find(params[:group_id])
        @project = Project.find(params[:project_id])
        @todo = @group.projects.todos.build(params[:todo])
        @todo.save
   ... 

If I write:

@todo = @group.todos.build(params[:todo]) 

or
@todo = @project.todos.build(params[:todo])

the project_id OR group_id is saved in the database. But not with:

@todo = @group.projects.todos.build(params[:todo])

My question is now, how I can get access of the group_id and the project_id and save them both into the database.

  • 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-19T00:26:58+00:00Added an answer on May 19, 2026 at 12:26 am

    Finally I found a working solution:

        @group  = Group.find(params[:group_id])
        @todo   = @group.todos.build(params[:todo])    
        @todo.project = Project.find(params[:project_id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem concerning translations in qt. All translations in my porject work fine,
I have problem in Listview onListItemClick() method. I am not getting the position of
I have a problem with converting a text file from ANSI to UTF8 in
I have got a problem with converting an NSNumber value to an NSString MyPowerOnOrNot
I have created branches for one project, but now I have a need to
We have a .Net 2.0 web app and are converting the solution and projects
I have a virtual windows server with SQL Server 2008 R2 Express. for the
I hope you can help me with a problem; first, please don't worry about
I am saving a image into database with byte[] property like this: ProfileModel: private
I have a task to convert the data design in XML format to a

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.