Lorenzo Brito Morales
2011-Feb-12 22:25 UTC
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
<td><%= link_to ''Say when'', todo, :action
=> :say_when ,
:remote => true %></td>
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
<h1>Listing todos</h1>
<table>
<tr>
<th>Tarea</th>
<th>Progreso</th>
<th>Show</th>
<th>Edit</th>
<th>Destroy</th>
<th>Add</th>
<th>Less</th>
</tr>
<% @todos.each do |todo| %>
<tr>
<td> <%= todo.todo %></td>
<td>
<span class=''progressBar'' id=''element<%=
todo.id %>''><%todo.progreso %></span>
</td>
<td><%= link_to ''Show'', todo %></td>
<td><%= link_to ''Edit'', edit_todo_path(todo)
%></td>
<td><%= link_to ''Destroy'', todo, :confirm =>
''Are you sure?'',
:method => :delete %></td>
<td><%= link_to ''Say when'', todo, :action
=> :say_when ,
:remote => true %></td>
<td></td>
</tr>
<% end %>
</table>
<br />
<%= link_to ''New Todo'', new_todo_path %>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Did you define it in your routes.rb? What is the output of rake routes? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lorenzo Brito Morales
2011-Feb-12 22:37 UTC
Re: Re: link_to a action in the controlles is not called
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"}
On Sat, Feb 12, 2011 at 4:34 PM, bourne
<bourne7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Did you define it in your routes.rb?
> What is the output of rake routes?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Lorenzo Brito Morales
2011-Feb-12 22:46 UTC
Re: Re: link_to a action in the controlles is not called
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 Morales
<lorenzo.brito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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"}
>
> On Sat, Feb 12, 2011 at 4:34 PM, bourne
<bourne7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Did you define it in your routes.rb?
>> What is the output of rake routes?
>>
>> --
>> You received this message because you are subscribed to the Google
Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To unsubscribe from this group, send email to
>>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Feb-13 07:45 UTC
Re: link_to a action in the controlles is not called
On Feb 12, 10:25 pm, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i have a link where it has to call a method defin in todoscontroller > named say_when but show is called > <td><%= link_to ''Say when'', todo, :action => :say_when , > :remote => true %></td> >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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lorenzo Brito Morales
2011-Feb-14 04:40 UTC
Re: Re: link_to a action in the controlles is not called
THANks, it works On Sun, Feb 13, 2011 at 1:45 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Feb 12, 10:25 pm, Lorenzo Brito Morales <lorenzo.br...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> i have a link where it has to call a method defin in todoscontroller >> named say_when but show is called >> <td><%= link_to ''Say when'', todo, :action => :say_when , >> :remote => true %></td> >> > > 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 > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.