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,
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.