On Tue, Nov 16, 2010 at 9:48 PM, Jason Hhh <li...@ruby-forum.com> wrote: > I have a rails app. I understand how to create a function in Rails. > > I have a contact that is viewable by multiple users. I want to create a > function to lock and unlock the contact. I have a field in the contact > database called locked. > > I assume I create a new function in the action controller or contact > controller like: > > def lock(contact_id) > c=Contact.find(contact_id) > c.locked = 1 > c.save > end > > def unlock(contact_id) > c=Contact.find(contact_id) > c.locked = 0 > c.save > end > > > Is this the proper way to do this? How do I make sure it's not > accessible through the through the URL: /Contacts/lock?
By keeping the function out of the controller. You may either place lock and unlock in a helper file, or make them as a part of the model itself. I, personally, vote for the latter. Rule of thumb: smart models, thin controller. Happy hacking! > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.