Skip to content

Move code into controller

Richard Huang edited this page Aug 15, 2010 · 3 revisions

Please go to http://rails-bestpractices.com/posts/24-move-code-into-controller

Before:


<% @posts = Post.find(:all) %>
<% @posts.each do |post| %>
  <%=h post.title %>
  <%=h post.content %>
<% end %>

After:


class PostsController < ApplicationController

  def index
    @posts = Post.find(:all)
  end

end