From dab47b8e01ad85170c475da0fd91be281fe5ea65 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 27 Nov 2018 04:55:49 -0600 Subject: [PATCH] universe serialization fixes --- app/models/serializers/content_serializer.rb | 8 ++++---- app/views/content/display/_contributors.html.erb | 2 +- app/views/content/form/_contributors.html.erb | 2 +- app/views/content/form/contributors/_leave.html.erb | 4 ++-- app/views/content/new.html.erb | 2 -- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/models/serializers/content_serializer.rb b/app/models/serializers/content_serializer.rb index 9dbdc103..4142b248 100644 --- a/app/models/serializers/content_serializer.rb +++ b/app/models/serializers/content_serializer.rb @@ -29,7 +29,7 @@ class ContentSerializer self.id = content.id self.name = content.name self.user = content.user - self.universe = content.universe + self.universe = content.is_a?(Universe) ? self : content.universe self.raw_model = content @@ -40,9 +40,9 @@ class ContentSerializer self.data = { name: content.try(:name), description: content.try(:description), - universe: content.universe_id.nil? ? nil : { - id: content.universe_id, - name: content.universe.try(:name) + universe: self.universe.nil? ? nil : { + id: self.universe.id, + name: self.universe.try(:name) }, categories: self.categories.map { |category| { diff --git a/app/views/content/display/_contributors.html.erb b/app/views/content/display/_contributors.html.erb index ad929cb1..58a0eadc 100644 --- a/app/views/content/display/_contributors.html.erb +++ b/app/views/content/display/_contributors.html.erb @@ -2,7 +2,7 @@

-<% if content.contributors.any? %> +<% if content.raw_model.contributors.any? %>

The following users are enabled as contributors to this universe. <% if user_signed_in? && content.user == current_user %> diff --git a/app/views/content/form/contributors/_leave.html.erb b/app/views/content/form/contributors/_leave.html.erb index 01917bbc..edccaad6 100644 --- a/app/views/content/form/contributors/_leave.html.erb +++ b/app/views/content/form/contributors/_leave.html.erb @@ -1,6 +1,6 @@ <%# Usage: render partial: 'content/form/contributors/leave', locals: { content: content } %> -<% if user_signed_in? && content.contributors.pluck(:user_id).include?(current_user.id) %> +<% if user_signed_in? && content.raw_model.contributors.pluck(:user_id).include?(current_user.id) %>

You are a contributor to this universe. You may dismiss yourself as a contributor at any time, but will need to be reinvited to begin contributing again. You will lose access to all content in this universe unless it is shared publicly, even if you created or edited it previously. @@ -12,4 +12,4 @@ method: 'delete', data: { confirm: "Are you sure? You will no longer have contributor access to this universe." } %>

-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/content/new.html.erb b/app/views/content/new.html.erb index 0a4fafb3..c42dad72 100644 --- a/app/views/content/new.html.erb +++ b/app/views/content/new.html.erb @@ -1,5 +1,3 @@ -<%= render 'attribute_fields/modal', content: @content %> -
<%= form_for @content, multipart: true do |form| %>