Hi people
I have an issue with trying to keep AR finders DRY in my application. I have created a blogging application which fetches all the related pages,posts,links,tags and categories for a blog when a user first views it. A sample show action for the Blog controller is shown below:
def show
#find blog by user name
@user= User.find_by_login(params[:id])
@blog= @user.blog
@posts = Post.status("publish",@user).find(:all, :order => "created_at DESC")
@tags = @user.tags
@pages = Page.status("publish",@user).find(:all, :order => "created_at DESC")
@links = @user.links.public_link.find(:all, :order => 'created_at DESC')
@archives = @posts.group_by(&:month)
@categories = @user.categories.group_by(&:name)
session[:found_user][email protected]
render :layout=>false
end
As you can see it is not very DRY as there are other actions which call upon the same instance variables such as @tags etc further in the controller.
How could I make this more DRY? I tried moving it into the Blog model but I still need to call the various instance variables such as @tags etc in the controller.
Is there a way to store all these variables when the blog is first called and re-use them across controllers and actions?
Thank you for any advice. I'm using Rails 2.1