adds tags to debates [#8]
This commit is contained in:
@@ -3,7 +3,11 @@ class DebatesController < ApplicationController
|
|||||||
before_action :authenticate_user!, only: [:new, :create]
|
before_action :authenticate_user!, only: [:new, :create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@debates = Debate.all
|
if params[:tag]
|
||||||
|
@debates = Debate.tagged_with(params[:tag])
|
||||||
|
else
|
||||||
|
@debates = Debate.all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@@ -35,7 +39,7 @@ class DebatesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def debate_params
|
def debate_params
|
||||||
params.require(:debate).permit(:title, :description, :external_link, :terms_of_service)
|
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,7 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
|
||||||
|
def tags(debate)
|
||||||
|
debate.tag_list.map { |tag| link_to tag, debates_path(tag: tag) }.join(', ').html_safe
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
<div class='debate'>
|
<div id="debate-<%= debate.id %>" class='debate'>
|
||||||
<p><%= link_to debate.title, debate %></p>
|
<p><%= link_to debate.title, debate %></p>
|
||||||
<p><%= debate.description %></p>
|
<p><%= debate.description %></p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Creado el: <%= l debate.created_at.to_date %>
|
Creado el: <%= l debate.created_at.to_date %>
|
||||||
por: <%= debate.author.name %>
|
por: <%= debate.author.name %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p><%= render 'shared/tags', debate: debate %></p>
|
||||||
</div>
|
</div>
|
||||||
<br/><br/>
|
<br/><br/><br/><br/>
|
||||||
@@ -20,6 +20,11 @@
|
|||||||
<p>Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguiríamos con ella</p>
|
<p>Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguiríamos con ella</p>
|
||||||
<%= f.text_area :description %>
|
<%= f.text_area :description %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= f.label :tag_list, "Temas (separados por comas)" %><br />
|
||||||
|
<%= f.text_field :tag_list, value: @debate.tag_list.to_s %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% if @debate.new_record? %>
|
<% if @debate.new_record? %>
|
||||||
<%= f.check_box :terms_of_service %>
|
<%= f.check_box :terms_of_service %>
|
||||||
Acepto la política de privacidad y el aviso legal
|
Acepto la política de privacidad y el aviso legal
|
||||||
|
|||||||
@@ -7,5 +7,8 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= render 'shared/tags', debate: @debate %>
|
||||||
|
|
||||||
|
<br/><br/>
|
||||||
<%= link_to 'Edit', edit_debate_path(@debate) %> |
|
<%= link_to 'Edit', edit_debate_path(@debate) %> |
|
||||||
<%= link_to 'Back', debates_path %>
|
<%= link_to 'Back', debates_path %>
|
||||||
3
app/views/shared/_tags.html.erb
Normal file
3
app/views/shared/_tags.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<% if debate.tags.any? %>
|
||||||
|
Temas: <%= tags(debate) %>
|
||||||
|
<% end %>
|
||||||
Reference in New Issue
Block a user