I am following along with Railscast 035 Custom REST Actions. I have everything working locally, but when I pushed to heroku, I am getting a page does not exist error for /tasks/2/complete
Heroku App GitHub Repo
When I click on complete task
link, I should create a put
request to the rails app's tasks#complete
action. Instead I am getting a 404 error. In my logs I have the following
method=GET path=/task/2/complete host=custom-rest-actions.herokuapp.com
request_id=16761046-c4fc-4164-b0bb-f6ed6191d71a fwd="98.207.180.92" dyno=web.1
connect=7ms service=19ms status=404 bytes=1829
heroku run rake routes
Prefix Verb URI Pattern Controller#Action
root GET / tasks#index
completed_tasks GET /tasks/completed(.:format) tasks#completed
complete_task PUT /tasks/:id/complete(.:format) tasks#complete
tasks GET /tasks(.:format) tasks#index
POST /tasks(.:format) tasks#create
new_task GET /tasks/new(.:format) tasks#new
edit_task GET /tasks/:id/edit(.:format) tasks#edit
task GET /tasks/:id(.:format) tasks#show
PATCH /tasks/:id(.:format) tasks#update
PUT /tasks/:id(.:format) tasks#update
DELETE /tasks/:id(.:format) tasks#destroy
Index.html.erb
<table>
<tbody>
<% @tasks.each do |task| %>
<tr>
<td><%= link_to task.name, task %></td>
<td>| <%= link_to 'Edit', edit_task_path(task) %></td>
<td><%= link_to 'Complete task', complete_task_path(task), method: :put %></td>
</tr>
<% end %>
</tbody>
</table>
Controller
def completed
@tasks = Task.where(completed: true)
end
def complete
@task.update_attribute :completed, true
flash[:notice] = 'Task Completed'
redirect_to completed_tasks_path
end
routes
resources :tasks do
get 'completed', on: :collection
put 'complete', on: :member
end
I don't think you need a view for that action because it redirects to the completed_tasks_path