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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:36:00+00:00 2026-06-06T09:36:00+00:00

I have an association between a project and a task. A project has_many taks

  • 0

I have an association between a project and a task.

A project has_many taks and a task belongs_to a project.

My model is working great. I can create tasks from project and so on.

My problem comes when I want to add a button on the project index view to add task to a
project.

What I want is something like that

(project index view)

Project 1 Show, edit, destroy, add_task

Project 2 Show, edit, destroy, add_task

So that when I click add_task of project 1 I’m redirected to a new task form to create a task for that project.

I’ve added <%= link_to ‘add_task’, new_task_path(:project_id =>
project) %> in the project index view, so when I click on add_task, it redirects me to /task/new?project_id=1

but when I submit the task, the task is not linked to the project.

How can I get the project_id?

Does anyone has a tutorial or an example of how should I do?

Thanks,

  • 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-06T09:36:02+00:00Added an answer on June 6, 2026 at 9:36 am

    Like Oscar suggested you might want to add an extra field in your form which submits the project_id to the params. then in either ur update or create function you can create the record using the parameter value, although on an hidden field make sure u set the value correctly.

    <%= f.hidden_field :project_id, :value => project.id%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a has_many and belongs_to association set up between two models: Project and
I have a working HABTM association between the models Posts and Users... the posts_users
I have a accepts_nested_attributes_for association between timesheet and timesheetlines. This works great, but when
I have a simple has_one/belongs_to relationship between two models. This is a new association
In my domain model I have a bi-directionnel association between the ProductList entity and
I have a Partner model that has_and_belongs_to_many Projects, while each Project has_many Sites. I
I have a has_one association between user and setting model. I have also SettingsController
I have a HABTM association between user and role. User can be an admin
I have a has_many through association between videos and topics, with topicable being the
I have a has_many, through association between videos and topics with topicables as the

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.