RESTful checkbox to complete task

Here’s where I am right now:

View:

<% for task in @tasks %>
<%= link_to “Complete”, complete_task_path(task) %>
<%=h task.body %>
<%= link_to ‘Edit’, edit_task_path(task) %>
<%= link_to ‘Destroy’, task, :confirm => ‘Are you sure?’, :method
=> :delete %>
<% end %>

routes.rb:
map.resources :tasks, :collection => { :complete => :post }

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

Right now I am getting undefined method for complete_task_path. Why is
that? And how do I turn this into a checkbox? I want the checkbox to
call the complete method.

You want to change :collection to :member.

On Dec 18, 2007 11:44 AM, jcontonio [email protected] wrote:

   <%= link_to 'Destroy', task, :confirm => 'Are you sure?', :method

@task = Task.find(params[:id])
@task.completed = true
end

Right now I am getting undefined method for complete_task_path. Why is
that? And how do I turn this into a checkbox? I want the checkbox to
call the complete method.


Ryan B.
http://www.frozenplague.net

I need to do more reading it looks like. Thank you Ryan

Heh, that stumped me a few times when I was learning restful routing
too.

The way I remember it now is a :member is like a member of a group,
whereas
a collection is a collection of things.

On Dec 18, 2007 11:51 AM, jcontonio [email protected] wrote:

   <%= link_to 'Destroy', task, :confirm => 'Are you sure?',

def complete


Ryan B.
http://www.frozenplague.net

That’s easy to remember. Thanks again

Maybe you can answer this Ryan.

Do I still do :render layout => false when pushing out an rjs format
when using a RESTful design? My complete.js.rjs isn’t being called.

def complete
@task = Task.find(params[:id])
@task.completed = true
render :layout => false
end

By default, RJS files are not rendered with a layout.

Are you sure it’s going in to the rjs file and the rjs file has valid
code?

Are you using Firefox? Do you have Firebug? Firebug will tell you about
any
javascript errors.

On Dec 18, 2007 11:58 AM, jcontonio [email protected] wrote:

end

:method

@task = Task.find(params[:id])
Ryan B.http://www.frozenplague.net


Ryan B.http://www.frozenplague.net


Ryan B.
http://www.frozenplague.net

Ah ok, here is my problem:

in my log I see:
Parameters: {“action”=>“3”, “id”=>“complete”, “controller”=>“tasks”}

That’s pretty weird no? Why would
<%= link_to “Complete”, complete_task_path(task) %>
let it think the action = the id?

I have this:
map.resources :tasks, :member => { :complete => :put }

above

map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

That is weird. Have you not defined map.resources :tasks, :collection =>
{
:complete => :post } above the default
map.connect’:controller/:action/:id’?

I think that’s what would be doing something like that, because it would
be
sending a url like /tasks/3/complete. Move the map.resources to above
this
default map.connect 'contro… and it should work.

On Dec 18, 2007 12:08 PM, jcontonio [email protected] wrote:

On Dec 17, 8:31 pm, “Ryan B.” [email protected] wrote:

@task = Task.find(params[:id])

a collection is a collection of things.

Here’s where I am right now:
:method

@task = Task.find(params[:id])


Ryan B.http://www.frozenplague.net


Ryan B.http://www.frozenplague.net


Ryan B.http://www.frozenplague.net


Ryan B.
http://www.frozenplague.net

Weird. That’s the only thing I can think of that could cause it.

On Dec 18, 2007 12:28 PM, jcontonio [email protected] wrote:

That is weird. Have you not defined map.resources :tasks, :collection =>
On Dec 18, 2007 12:08 PM, jcontonio [email protected] wrote:

That’s pretty weird no? Why would

Are you using Firefox? Do you have Firebug? Firebug will tell you

when using a RESTful design? My complete.js.rjs isn’t being
routing

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