I have a Log model that belongs to User and Firm. For setting this I have this code in the logs_controller's create action.
def create
@log = Log.new(params[:log])
@log.user = current_user
@log.firm = current_firm
@log.save
end
current_user and current_firm are helper methods from the application_helper.rb
While this works it makes the controller fat. How can I move this to the model?
attr_accessible. One reason I like this in a worker class is it helps enforce a single point of entry for creating model instances, as well as enforcing that the necessary relations will be setup (though validation will also help with this; the worker method's signature helps act as a guide). It also makes testing the functionality that will be found in the controller for manipulating models dead simple.