Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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