Recent Posts by Anthony Stauffer
|
Dec 12, 2007
|
Topic: Ruby / Heroku.com That. Is. Awesome. This is scary. Just the other day I was thinking to myself “Wouldn’t it be great if someone would think up a way to a CMS like ruby on rails application, where you create, develop and edit your application online instead of on your own desktop. And here it is. Wow. |
|
Dec 12, 2007
|
Topic: Meta / Topics for Wed, Dec 13 Rails 2.0, specifically ActiveResource, and Restful improvements |
|
Oct 10, 2007
|
Topic: Ruby / RoR Technical Questions A model needs a controller if it’s going to have any interface to the web. For example, if I have a model called Employee.rb that maps to a database table named employees, If I want to be able to have a page to edit an employee’s details I need to have a controller that exposes the “edit” action. Like Scott said, Rails figures out what to do by parsing the url into “controller”/”action”/”id”. So if I go to www.examplerailsapp.com/employees/edit/12 , Rails will look for a controller called employee_controller, then try to find an action named “edit”, and perform that action passing in 12 as the id number of the employee to edit. If I had no controller for the model, I could only reference that model from other controllers in order to manipulate instances of that model. For example I may have anoter model named Store, and a corresponding controller called store_controller. I could implement an action inside of store_controller called “edit_employee”. In order to edit the details for an employee I would use a URL like www.examplerailsapp.com/store/edit_employee/12 . Rails would then find this action inside the store_controller and that code could load the Employee model out of the database using the supplied id number, present a form to the client, and update the employee when the form is submitted. However, I belive it’s generally bad form to present management of one type of object through another object’s controller. Scott can correct me on this if I’m wrong, but doing this starts to make it hard to reliably know where an object is managed from. |