Link_to a action in the controlles is not called

i have a link where it has to call a method defin in todoscontroller
named say_when but show is called

<%= link_to ‘Say when’, todo, :action => :say_when ,
:remote => true %>

class TodosController < ApplicationController

GET /todos

GET /todos.xml

def index
@todos = Todo.all

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @todos }
end

end

GET /todos/1

GET /todos/1.xml

def show
@todo = Todo.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @todo }
end

end

GET /todos/new

GET /todos/new.xml

def new
@todo = Todo.new

respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @todo }
end

end

GET /todos/1/edit

def edit
@todo = Todo.find(params[:id])
end

POST /todos

POST /todos.xml

def create
@todo = Todo.new(params[:todo])

respond_to do |format|
  if @todo.save
    format.html { redirect_to(@todo, :notice => 'Todo was

successfully created.’) }
format.xml { render :xml => @todo, :status => :created,
:location => @todo }
else
format.html { render :action => “new” }
format.xml { render :xml => @todo.errors, :status =>
:unprocessable_entity }
end
end
end

PUT /todos/1

PUT /todos/1.xml

def update
@todo = Todo.find(params[:id])

respond_to do |format|
  if @todo.update_attributes(params[:todo])
    format.html { redirect_to(@todo, :notice => 'Todo was

successfully updated.’) }
format.xml { head :ok }
else
format.html { render :action => “edit” }
format.xml { render :xml => @todo.errors, :status =>
:unprocessable_entity }
end
end
end

DELETE /todos/1

DELETE /todos/1.xml

def destroy
@todo = Todo.find(params[:id])
@todo.destroy

respond_to do |format|
  format.html { redirect_to(todos_url) }
  format.xml  { head :ok }
end

end

def say_when
 puts "hey i am callinf from ajax request"
respond_to do |format|
format.html { render(:layout => false)  }
end

end
end

here is teh view

Listing todos

<% @todos.each do |todo| %>

<td></td>
<% end %>
Tarea Progreso Show Edit Destroy Add Less
<%= todo.todo %> <%= todo.progreso %> <%= link_to 'Show', todo %> <%= link_to 'Edit', edit_todo_path(todo) %> <%= link_to 'Destroy', todo, :confirm => 'Are you sure?', :method => :delete %> <%= link_to 'Say when', todo, :action => :say_when , :remote => true %>

<%= link_to ‘New Todo’, new_todo_path %>

Did you define it in your routes.rb?
What is the output of rake routes?

is not, how i do that ?

todos GET /todos(.:format)
{:action=>“index”, :controller=>“todos”}
POST /todos(.:format)
{:action=>“create”, :controller=>“todos”}
new_todo GET /todos/new(.:format)
{:action=>“new”, :controller=>“todos”}
edit_todo GET /todos/:id/edit(.:format)
{:action=>“edit”, :controller=>“todos”}
todo GET /todos/:id(.:format)
{:action=>“show”, :controller=>“todos”}
PUT /todos/:id(.:format)
{:action=>“update”, :controller=>“todos”}
DELETE /todos/:id(.:format)
{:action=>“destroy”, :controller=>“todos”}
tags GET /tags(.:format)
{:action=>“index”, :controller=>“tags”}
POST /tags(.:format)
{:action=>“create”, :controller=>“tags”}
new_tag GET /tags/new(.:format)
{:action=>“new”, :controller=>“tags”}

i already added
resources :todos do
member do
get ‘say_when’
end
end
now its print DELETE /tiptags/:id(.:format)
{:action=>“destroy”, :controller=>“tiptags”}
say_when_todo GET /todos/:id/say_when(.:format)
{:action=>“say_when”, :controller=>“todos”}
todos GET /todos(.:format)
{:action=>“index”, :controller=>“todos”}
POST /todos(.:format)
{:action=>“create”, :controller=>“todos”}
new_todo GET /todos/new(.:format)
{:action=>“new”, :controller=>“todos”}
edit_todo GET /todos/:id/edit(.:format)
{:action=>“edit”, :controller=>“todos”}
todo GET /todos/:id(.:format)
{:action=>“show”, :controller=>“todos”}
PUT /todos/:id(.:format)
{:action=>“update”, :controller=>“todos”}
DELETE /todos/:id(.:format)
{:action=>“destroy”, :controller=>“todos”}

but the same happens

On Sat, Feb 12, 2011 at 4:37 PM, Lorenzo Brito M.

On Feb 12, 10:25pm, Lorenzo Brito M. [email protected]
wrote:

i have a link where it has to call a method defin in todoscontroller
named say_when but show is called

<%= link_to 'Say when', todo, :action => :say_when , :remote => true %>

The problem is that (by definition) this links to the show action for
a todo (the second argument to link_to specifies what the link should
point at) If you want it to link to something else, then, after you’ve
added it to routes.rb, you can write something like link_to ‘Say
when’, say_when_todo(todo), …

Fred

THANks, it works

On Sun, Feb 13, 2011 at 1:45 AM, Frederick C.