def remove_req
@posts = Post.find_all_by_requirement_id(params[:id])
@posts.each do |post|
post.destroy
end
redirect_to :action => :index
end
<%= link_to ''Remove'', :url => { :action =>
''remove_req'' },
:id=>post.requirement_id, :method => :delete %></td>
Doesn''t work, any tips?
Thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
remove_req.rjs
page.replace_html :main-body, :partial =>
''requirement_list''
view:
<%= link_to_remote ''Remove'', :url => { :action =>
''remove_req'' }, :with
=> "''id=#{post.requirement_id}''" %>
control:
def remove_req
Post.delete_all "requirement_id = #{params[:id]}"
respond_to do |format|
format.html { redirect_to :action => :index }
format.js { flash[:notice] = "ok" }
end
end
It doesn''t replace the html =(
Suggestions?
Thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Justin To wrote:> def remove_req > @posts = Post.find_all_by_requirement_id(params[:id]) > > @posts.each do |post| > post.destroy > end > > redirect_to :action => :index > end > > <%= link_to ''Remove'', :url => { :action => ''remove_req'' }, > :id=>post.requirement_id, :method => :delete %></td>Put the :id inside the :url. From outside, it might be the HTML id.> Doesn''t work, any tips?Put the deleter into a class method on Post. Write a unit test for it. (Actually, write the test first, then put the deleter in, but that''s an advanced topic...) Get the test to pass, by detecting Post.find_by_requirement_id() returns nil. Don''t use find_all_by_requirement_id if your params[:id] can only have one. Then write a "functional" test checking that your action deletes the target record. And don''t use :method => :delete in your link. That links to a magic HTTP verb DELETE, which you probably are not implementing. Try :method => :post. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---