Add communities and topics
This commit is contained in:
19
app/controllers/communities_controller.rb
Normal file
19
app/controllers/communities_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class CommunitiesController < ApplicationController
|
||||
|
||||
before_action :set_community, :load_topics, only: :show
|
||||
|
||||
skip_authorization_check
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_community
|
||||
@community = Community.find(params[:id])
|
||||
end
|
||||
|
||||
def load_topics
|
||||
@topics = @community.topics
|
||||
end
|
||||
end
|
||||
47
app/controllers/topics_controller.rb
Normal file
47
app/controllers/topics_controller.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
class TopicsController < ApplicationController
|
||||
|
||||
before_action :set_community
|
||||
|
||||
skip_authorization_check
|
||||
|
||||
def new
|
||||
@topic = Topic.new
|
||||
end
|
||||
|
||||
def create
|
||||
@topic = Topic.new(topic_params.merge(author: current_user, community_id: params[:community_id]))
|
||||
|
||||
if @topic.save
|
||||
redirect_to community_path(@community), notice: I18n.t('flash.actions.create.topic')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@topic = Topic.find(params[:id])
|
||||
end
|
||||
|
||||
def edit
|
||||
@topic = Topic.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@topic = Topic.find(params[:id])
|
||||
if @topic.update(topic_params)
|
||||
redirect_to community_path(@community), notice: t('topic.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_params
|
||||
params.require(:topic).permit(:title, :community_id)
|
||||
end
|
||||
|
||||
def set_community
|
||||
@community = Community.find(params[:community_id])
|
||||
end
|
||||
end
|
||||
6
app/models/community.rb
Normal file
6
app/models/community.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Community < ActiveRecord::Base
|
||||
has_one :proposal
|
||||
has_one :investment
|
||||
has_many :topics
|
||||
|
||||
end
|
||||
@@ -23,6 +23,7 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
belongs_to :geozone
|
||||
belongs_to :community
|
||||
has_many :comments, as: :commentable
|
||||
has_many :proposal_notifications
|
||||
|
||||
@@ -43,6 +44,7 @@ class Proposal < ActiveRecord::Base
|
||||
before_validation :set_responsible_name
|
||||
|
||||
before_save :calculate_hot_score, :calculate_confidence_score
|
||||
before_create :associate_community
|
||||
|
||||
scope :for_render, -> { includes(:tags) }
|
||||
scope :sort_by_hot_score, -> { reorder(hot_score: :desc) }
|
||||
@@ -180,6 +182,11 @@ class Proposal < ActiveRecord::Base
|
||||
(voters + followers).uniq
|
||||
end
|
||||
|
||||
def associate_community
|
||||
community = Community.create
|
||||
self.community_id = community.id
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_responsible_name
|
||||
|
||||
4
app/models/topic.rb
Normal file
4
app/models/topic.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Topic < ActiveRecord::Base
|
||||
belongs_to :community
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
end
|
||||
@@ -41,4 +41,3 @@
|
||||
<div id="investments">
|
||||
<%= render '/admin/budget_investments/investments' %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -41,4 +41,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= paginate @budgets %>
|
||||
<%= paginate @budgets %>
|
||||
|
||||
17
app/views/communities/show.html.erb
Normal file
17
app/views/communities/show.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
Comunidad de usuarios
|
||||
<br>
|
||||
<%= @community.proposal.title %>
|
||||
<br>
|
||||
Participa en la comunidad de esta propuesta
|
||||
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
<div id="topics">
|
||||
<%= render "topics/topics", topics: @community.topics %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
Participa
|
||||
<%= link_to t("topic.new"), new_community_topic_path(@community.id), class: 'button expanded' %>
|
||||
</div>
|
||||
@@ -89,12 +89,12 @@
|
||||
<aside class="margin-bottom">
|
||||
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button expanded' %>
|
||||
<% if params[:retired].blank? %>
|
||||
<%= render 'categories' %>
|
||||
<%= render "shared/tag_cloud", taggable: 'proposal' %>
|
||||
<%= render 'geozones' %>
|
||||
<%= render 'popular' %>
|
||||
<% end %>
|
||||
<%= render 'retired' %>
|
||||
<%= render 'categories' %>
|
||||
<%= render "shared/tag_cloud", taggable: 'proposal' %>
|
||||
<%= render 'geozones' %>
|
||||
<%= render 'popular' %>
|
||||
<% end %>
|
||||
<%= render 'retired' %>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -158,6 +158,7 @@
|
||||
<% if current_user %>
|
||||
<%= render 'follows/follow_button', follow: find_or_build_follow(current_user, @proposal) %>
|
||||
<% end %>
|
||||
<%= link_to t("community.show.access"), community_path(@proposal.community_id), class: 'button expanded' %>
|
||||
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
15
app/views/topics/_form.html.erb
Normal file
15
app/views/topics/_form.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<%= form_for([@community, @topic]) do |f| %>
|
||||
|
||||
<%= render 'shared/errors', resource: @topic %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= f.label :title, t("topic.form.topic_title") %>
|
||||
<%= f.text_field :title %>
|
||||
</div>
|
||||
|
||||
<div class="actions small-12 column">
|
||||
<%= f.submit(class: "button", value: t("topic.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
16
app/views/topics/_topics.html.erb
Normal file
16
app/views/topics/_topics.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div class="order">
|
||||
Ordenar por:
|
||||
</div>
|
||||
<br>
|
||||
<% if topics.any? %>
|
||||
<% topics.each do |topic| %>
|
||||
<div id="<%= dom_id(topic) %>">
|
||||
<%= link_to topic.title, community_topic_path(@community, topic) %>
|
||||
<% if topic.author == current_user %>
|
||||
<%= link_to t("topic.edit"), edit_community_topic_path(@community.id, topic), class: 'button expanded' %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
Crea el primer tema de la comunidad!!!
|
||||
<% end %>
|
||||
10
app/views/topics/edit.html.erb
Normal file
10
app/views/topics/edit.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="topic-form row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= render "shared/back_link" %>
|
||||
|
||||
<h1><%= t("topic.edit.editing") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
12
app/views/topics/new.html.erb
Normal file
12
app/views/topics/new.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="topic-new row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h1><%= t("topic.create") %></h1>
|
||||
|
||||
<%= render '/topics/form' %>
|
||||
<%#= render '/topics/form', form_url: budget_investments_path(@budget) %>
|
||||
</div>
|
||||
<div class="small-12 medium-9 column">
|
||||
Recomendaciones para crear un tema
|
||||
</div>
|
||||
|
||||
</div>
|
||||
5
app/views/topics/show.html.erb
Normal file
5
app/views/topics/show.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= render "shared/back_link" %>
|
||||
<br>
|
||||
Comunidad: <%= @community.proposal.title %>
|
||||
<br>
|
||||
<%= @topic.title %>
|
||||
Reference in New Issue
Block a user