This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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