Skip to content

Commit

Permalink
thin story serialzer and list out recent stories on the projects
Browse files Browse the repository at this point in the history
  • Loading branch information
colinyoung87 committed Oct 29, 2015
1 parent df37dd5 commit c42188e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/templates/projects/index.jst.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
</h3>

<ul class="recent-stories">
<li>No recent stories</li>
<li ng-hide="project.stories.length > 0">No recent stories</li>
<li ng-repeat="story in project.stories">
<span class="when">{{ story.updated_at }}</span>
<a href="/projects/{{ project.slug }}/stories/{{ story.slug }}">{{ story.name }}</a>
</li>
</ul>
</section>

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProjectsController < BaseController

api! "Fetch all projects"
def index
render json: current_user.projects.includes(:users).all
render json: current_user.projects.includes(:users, :stories).all
end

api! "Fetch a single project"
Expand Down
7 changes: 6 additions & 1 deletion app/serializers/project_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class ProjectSerializer < ActiveModel::Serializer
attributes :id, :name, :slug, :owner_id, :created_at, :updated_at, :deleted_at, :team_id
has_many :users
has_many :users, serializer: UserSerializer
has_many :stories, serializer: ThinStorySerializer

def stories
object.stories.order(updated_at: :desc).take(5)
end
end
3 changes: 3 additions & 0 deletions app/serializers/thin_story_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ThinStorySerializer < ActiveModel::Serializer
attributes :id, :name, :slug, :updated_at
end

0 comments on commit c42188e

Please sign in to comment.