Hi, I have a page containing 3 views (2 are partials). One of the partials needs to have a button that will clear a table called "messages" in the database. I can put a button like this "<%= button_to "Clear Messages", :action => ''clear_messages'' %>" and have the controller do "Message.delete_all". But the problem is that the controller would want to render a view, and I don''t want that to happen. I just want a particular action to occur in the backend without any changes to the page. Actually I would need such buttons for other purposes too, but if I know how to do the above example I could do the rest. Any help would be greatly appreciated. Thanks, Aditya -- Posted via http://www.ruby-forum.com/.
def clear_messages Message.delete_all render :nothing => true end You also will need to make you button_to a button_to_remote for an ajax call On 8/18/06, Aditya Rajgarhia <adityar7@gmail.com> wrote:> > Hi, > > I have a page containing 3 views (2 are partials). One of the partials > needs to have a button that will clear a table called "messages" in the > database. > > I can put a button like this "<%= button_to "Clear Messages", :action => > ''clear_messages'' %>" and have the controller do "Message.delete_all". > But the problem is that the controller would want to render a view, and > I don''t want that to happen. I just want a particular action to occur in > the backend without any changes to the page. > > Actually I would need such buttons for other purposes too, but if I know > how to do the above example I could do the rest. > > Any help would be greatly appreciated. Thanks, > > Aditya > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/6cf2ed65/attachment.html
Thanks for the reply Mark. Unfortunately, I had tried your solution already. The problems are:> render :nothing => trueThis renders a blank page. It would not do that if the call were Ajax, but:> You also will need to make you button_to a button_to_remote for an ajax > callActually, button_to_remote doesn''t exist :( -- Posted via http://www.ruby-forum.com/.
> > > Actually, button_to_remote doesn''t exist :( >true! You can use a link_to_remote also, or just do a normal button and add you own ajax call in the onclick. -- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/92f2c357/attachment.html