Tag Archives: Refactoring

Chaining Create Methods to an Object Instance

In my Rails controllers, I have a lot of this:
 
@project = Project.find(params[:project])
if @project
@project_product = @project.project_products.create(params[:project_product])
if @project_product.valid?
# Do something with success
else
# Do something with error
end
else
# Do something with error
end
 
The thing that I don’t like about that style is that the […]