Bob Sanders
2007-Jun-18 00:15 UTC
Click On a Link to Update Database Record. How Do You Do It?
I''m experimenting with creating a very small To-Do List. I want to be able to click on a link that says: "Complete This To-Do Item" right beside the item -- and then the database field underneath, "Status", will update from "Open" to "Completed". How would you do it? (Also, if there''s a better way to do this, I''m open ears :) -- 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 -~----------~----~----~----~------~----~------~--~---
Jeff
2007-Jun-18 01:08 UTC
Re: Click On a Link to Update Database Record. How Do You Do It?
On Jun 17, 7:15 pm, Bob Sanders <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m experimenting with creating a very small To-Do List. > > I want to be able to click on a link that says: "Complete This To-Do > Item" right beside the item -- and then the database field underneath, > "Status", will update from "Open" to "Completed". > > How would you do it? > > (Also, if there''s a better way to do this, I''m open ears :)Learn about controllers and actions in Rails. I would recommend the Agile Web Development with Rails or Ruby for Rails as good books to start with. Eventually you''ll learn about the link_to helper you can use in your views, for example: <% link_to ''Complete This To-Do Item'', :action => ''completed'' %> and you have to implement the corresponding ''completed'' action in your controller. But that''s a lot to explain here, so start with one of the books above. Jeff softiesonrails.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 -~----------~----~----~----~------~----~------~--~---
Chris T
2007-Jun-26 09:58 UTC
Re: Click On a Link to Update Database Record. How Do You Do It?
Bob Sanders wrote:> I''m experimenting with creating a very small To-Do List. > > I want to be able to click on a link that says: "Complete This To-Do > Item" right beside the item -- and then the database field underneath, > "Status", will update from "Open" to "Completed". > > How would you do it? > > (Also, if there''s a better way to do this, I''m open ears :) > >My recommendation would be to start with a non-Ajax version, and then add the Ajax behaviour in unobtrusively afterwards (something like LowPro or UJS). I would recommend that the (GET) link goes to a confirmation page, which then POSTs the update (destructive GET requests are not a good idea). Then add the Ajax functionality on top of that, to submit the POST directly from the link. That way you have nicely degrading clean code. Hope this makes sense. I do something exactly like this on Autopendium, with the following code apply_behaviour ''input.todo_complete_box'', make_observed(:field, {:url => {:controller => ''todos'', :action => ''update'', :id => nil}, :method => "put", :with => "''id='' + element.id.replace(''todo_complete_box_'','''') + ''&todo[completed]='' + (element.checked ? 1 : 0) "}) The apply_behavour is from the UJS plugin, and you actually tick or un-tick checkboxes (which only show if JS is enabled). Hope this helps, Chris -- ---------------------------- http://autopendium.com Stuff about old cars --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---