Can I use an if statement in my controller or is this bad practice?
In both my create and destroy actions for TracksController, I want to do something like this:
if Product
@product = Product.find(params[:product_id])
@track = @product.tracks.create(params[:track])
eslif Release
@Release = Release.find(params[:release_id])
@track = @release.tracks.create(params[:track])
end
Is there a better way to do this?
I’d go further and suggest a more DRY approach to the before_filter:
I used parent because we were given a context for the model relationships but I assume there’s a better term to describe the commonality between release and product wrt tracks.