Topic: How to clean this up
This has been nagging me for a while and it seems if I try to keep light controllers & heavy models, there would be a better way to do this. I just don't see a huge benefit to this approach, I want to hear others thoughts, or if this is proper. I find myself doing all of it in the controller rather than creating an extra model method.
lets say I have a Movie model. I want to mark my movies as "available"
Currently I have a controller method called "mark_as_available"
def mark_as_available movie = Movie.find(params[:id]) movie.available = true if movie.save! flash[:notice] = "Movie has been set as available." end end
How could I clean this up and put it in the Movie model rather than the controller? I'm assuming I could create a method called "mark_as_available" and simply call it like this...
def mark_as_available movie = Movie.find(params[:id]) if movie.mark_as_available flash[:notice] = "Movie has been set as available." end end
def mark_as_available self.available = true end
Last edited by internetchris (2011-03-14 17:11:38)