Thursday, 15 September 2011

ruby on rails - Avoiding scope usage in views -


Due to specific results, I want to render, I am currently using Scope in my thoughts. I know that this is probably not the best idea, but I honestly do not have any clue how to reuse it properly.

  @ category = category> all> # post. RB region: published, - & gt; {Post.all.where (Published: true) .order ('created_at DESC')} # Category RB DR def_posts posts.published end  

view

  @ categories.Each | Category | Do Category.published_posts.each | Posted in | ... Continue posting by post #  

As you can see, I'm using publish_pose in my view, do you think it's okay, or do I Should it be re-used in any way?

Good it depends. It is okay to call scope in the scenes. It is good as the calling method on the object now it depends on whether you want to preprocess on the post before you pass the post to see or decorate it, Can take over

There will be one more example, suppose that you have promoted the post, you want to add a post that receives more logic and want to send it to show.

At the end of the day, I want to put less business logic into ideas. Just pass the data and present it


No comments:

Post a Comment