i have a link where it has to call a method defin in todoscontroller
named say_when but show is called
: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
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 %>