diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 718772015..2bf5a0024 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -3,7 +3,11 @@ class DebatesController < ApplicationController before_action :authenticate_user!, only: [:new, :create] def index - @debates = Debate.all + if params[:tag] + @debates = Debate.tagged_with(params[:tag]) + else + @debates = Debate.all + end end def show @@ -35,7 +39,7 @@ class DebatesController < ApplicationController end 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..74dcfd229 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,7 @@ module ApplicationHelper + + def tags(debate) + debate.tag_list.map { |tag| link_to tag, debates_path(tag: tag) }.join(', ').html_safe + end + end diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 637c0086c..d78776af9 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -1,9 +1,12 @@ -
+

<%= link_to debate.title, debate %>

<%= debate.description %>

+

Creado el: <%= l debate.created_at.to_date %> por: <%= debate.author.name %>

+ +

<%= render 'shared/tags', debate: debate %>

-

\ No newline at end of file +



\ No newline at end of file diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 4ece98d8f..9d0af3892 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -20,6 +20,11 @@

Explica con todo el detalle que puedas y de una manera sencilla la idea y que crees que conseguirĂ­amos con ella

<%= f.text_area :description %> +
+ <%= f.label :tag_list, "Temas (separados por comas)" %>
+ <%= f.text_field :tag_list, value: @debate.tag_list.to_s %> +
+ <% if @debate.new_record? %> <%= f.check_box :terms_of_service %> Acepto la polĂ­tica de privacidad y el aviso legal diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index f0a67e527..2b0d88b7c 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -7,5 +7,8 @@

+<%= render 'shared/tags', debate: @debate %> + +

<%= link_to 'Edit', edit_debate_path(@debate) %> | <%= link_to 'Back', debates_path %> \ No newline at end of file diff --git a/app/views/shared/_tags.html.erb b/app/views/shared/_tags.html.erb new file mode 100644 index 000000000..990c0d41f --- /dev/null +++ b/app/views/shared/_tags.html.erb @@ -0,0 +1,3 @@ +<% if debate.tags.any? %> + Temas: <%= tags(debate) %> +<% end %> \ No newline at end of file