Created
October 4, 2012 14:26
-
-
Save tdm00/3833847 to your computer and use it in GitHub Desktop.
Dashboard of posts and comments
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 Comment < ActiveRecord::Base | |
# Associations | |
belongs_to :post | |
belongs_to :commenter | |
end |
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 Commenter < ActiveRecord::Base | |
# Associations | |
has_many :comments | |
end |
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
<% @posts.each do |post| %> | |
<%= post.title %> <br> | |
# what to loop over the comments here, there maybe more then one, and show the commenter name | |
# for example output: | |
# This is my first post | |
# - john said this is great | |
# - tom said i hope the tigers win | |
# This is my second post | |
# how do I do this? | |
- <%= post.comment.commenter.name %> said <%= post.comment.body %> | |
<% end %> |
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 MainController < ApplicationController | |
def main | |
@posts = Post.includes(:comments => {:commenter}) | |
respond_to do |format| | |
format.html # dashboard.html.erb | |
format.json { render json: @requisitiontestreports } | |
end | |
end | |
end |
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 Post < ActiveRecord::Base | |
# Associations | |
has_many :comments | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment