I have two controllers: workers and tasks.
this is the variable index of the tasks_controller:
def index
@task = Worker.where(:name => params[:worker_id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @worker }
end
end
this is my index.html.erb of Tasks:
<table>
<% @task.each do |task| %>
<tr>
<td><%= task.name %></td>
<td><%= task.task %></td>
<td><%= task.done %></td>
<td><%= link_to 'Edit', edit_worker_task_path(task.name,1) %></td>
</tr>
<% end %>
</table>
I have to know what is the id of the task (for example, I set ‘1’).

I attach my rake routes command:
This is my edit of the task (I just wanted to see if I get the relevant task):
<table>
<% @task.each do |task| %>
<tr>
<td><%= task.name %></td>
<td><%= task.task %></td>
<td><%= task.done %></td>
</tr>
<% end %>
</table>
and this is my models/worker.rb:
class Worker < ActiveRecord::Base
attr_accessible :done, :name, :task
end
To link to the edit page for a particular task, just this will do:
If that is a nested route you probably want to ensure there is a edit_task route so you can do this:
But as your @task variable is actually a collection of Worker models, if you called the edit_task_path(task) helper then you’ll end up on the edit task page, but it’ll have passed through the id of a Worker. Does that make sense?
Edit
After a bit of a chat, we created the necessary Task and Worker models, sorted out the migrations and routes.rb file. Then pointed him towards
new_worker_task_path(worker)and looked at the worker index page.