avatar

Neil Robinson

Rails Models

Picture of a Rails ActionView field_for :tag example

Rails Transaction Do

ActiveRecord Transactions

You can commit atomic transactions on an ActiveRecord model by calling class method Model.transaction do. This allows the update controller action to update all associated models in one transaction. I have previously wondered how to make sure you can update all your associated models in one big committed transaction and ensure all models are updated through the controller. Now I learned it is using the transaction do block.

Picture of a Database Schema

Rails Associations

In Ruby on Rails, the MVC concept is easy to follow when you have a non-relational type of model. The difficulty with rails is that I find organizing and creating the MVC around multiple model associations. The resources and views of associated models seem linked together and brittle. As if I make a change and it breaks a lot of the default views code or the create and update actions. I fear I am misunderstanding rails. I looked through all the guides and there doesn’t appear to be good explanation for how to deal with the views of complex associations. Even on the web, there seems to be limited discussion on this topic.