Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created July 31, 2009 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasjhenry/159227 to your computer and use it in GitHub Desktop.
Save nicholasjhenry/159227 to your computer and use it in GitHub Desktop.
class WeblogController < ActionController::Base
# will render weblog/index.html.erb
# note for older versions it will be index.rhtml, but it's still erb
def index
# more code here
end
end
class AuthorsController < ActionController::Base
# will render authors.index.html.erb
def index
@authors = Author.find(:all)
end
end
# in weblog/index.html.erb
<%= render_component :controller => "authors", :action => "index" %>
# refactoring
class WeblogController < ActionController::Base
before_filter :find_authors
# will render weblog/index.html.erb
def index
# more code here
end
private
def find_authors
@authors = Author.find(:all) # Since v2.2(I think) you can do Author.all
end
end
# in weblog/index.html.erb
<%= render :partial => 'author', :collection => @authors %> # to render authors/author for each record in @authors
# also in v2.3 above you can simply do
<%= render @authors %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment