REST and custom routes

So here’s what I do and lets see if someone can solve the problems

rails test
cd test
script/generate scaffold Task body:string completed:boolean
rake db:create
rake db:migrate

#routes.rb
map.resources :tasks, :member => {:complete => :post}
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

#tasks_controller.rb
def complete
@task = Task.find(params[:id])
@task.completed = true
end

#index.html.erb

<%=h task.body %> <%=h task.completed %> <%= link_to 'Show', task %> <%= link_to 'Edit', edit_task_path(task) %> <%= link_to 'Destroy', task, :confirm => 'Are you sure?', :method => :delete %> <%= link_to 'Complete', complete_task_path(task) %>

script/server

Now, add a task then go back to index
Click the Complete link and watch it go:

Unknown action
No action responded to 1

And here’s what it’s doing in the log:
Parameters: {“action”=>“1”, “id”=>“complete”, “controller”=>“tasks”}

Why isn’t it recognizing it as action => complete, id => 1 ?

I can reproduce this every time so there’s nothing I’m doing that
might trigger something like this.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs