trying to get rails routing to “click” and just not getting it
have a project and a task model:
class Task
include Mongoid::Document
field :title, :type => String
has_many :projects
belongs_to :user
end
class Project
include Mongoid::Document
field :title, :type => String
has_and_belongs_to_many :tasks
belongs_to :user
end
I want to “associate” a task with a project
so I have this in the project controller:
def connect
@project = Project.find(params[:id])
@project.tasks_ids.push(params[:task_id])
@project.save
redirect_to project
end
with this route:
resources :projects do
match 'connect/:id' => 'projects#connect', :as => :connect, :via => :put
resources :tasks
end
I cant seem to get this to work in the view:
= link_to 'Associate Task', project_connect_path(@task)
fails with:
No route matches {:controller=>”projects”, :action=>”connect”}
Your path should look like this:
= link_to ‘Associate Task’, project_connect_path(@project, :task_id => @task.id), :method => :put