diff --git a/Gemfile b/Gemfile index 3f6d2b90e..09a70cfe5 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'devise' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development - +gem 'acts-as-taggable-on' gem "responders" gem 'foundation-rails' gem 'acts_as_votable' diff --git a/Gemfile.lock b/Gemfile.lock index d0dfefaaa..9124a06fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + acts-as-taggable-on (3.5.0) + activerecord (>= 3.2, < 5) acts_as_votable (0.10.0) arel (6.0.2) bcrypt (3.1.10) @@ -189,6 +191,7 @@ PLATFORMS ruby DEPENDENCIES + acts-as-taggable-on acts_as_votable byebug capybara diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss new file mode 100644 index 000000000..cb4df7794 --- /dev/null +++ b/app/assets/stylesheets/debates.scss @@ -0,0 +1,7 @@ +#tag_cloud { + width: 400px; + line-height: 1.6em; + .s { font-size: 0.8em; } + .m { font-size: 1.2em; } + .l { font-size: 1.8em; } +} \ No newline at end of file diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 53545887e..2bf5a0024 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,8 +1,13 @@ class DebatesController < ApplicationController before_action :set_debate, only: [:show, :edit, :update] - + 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 @@ -16,7 +21,9 @@ class DebatesController < ApplicationController end def create - @debate = Debate.create(debate_params) + @debate = Debate.new(debate_params) + @debate.author = current_user + @debate.save respond_with @debate end @@ -32,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/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 000000000..4ccafe235 --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,9 @@ +class RegistrationsController < Devise::RegistrationsController + + private + + def sign_up_params + params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..e3f79f023 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 sanitize(tag), debates_path(tag: tag) }.join(', ').html_safe + end + end diff --git a/app/models/debate.rb b/app/models/debate.rb index 5e810d061..727d805e7 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,9 +1,13 @@ require 'numeric' class Debate < ActiveRecord::Base acts_as_votable + acts_as_taggable + + belongs_to :author, class_name: 'User', foreign_key: 'author_id' validates :title, presence: true validates :description, presence: true + validates :author, presence: true validates :terms_of_service, acceptance: { allow_nil: false }, on: :create @@ -24,4 +28,5 @@ class Debate < ActiveRecord::Base def total_votes votes_for.size end + end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index c8220270d..9c55bc59e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,8 @@ class User < ActiveRecord::Base - # Include default devise modules. Others available are: - # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + def name + "#{first_name} #{last_name}" + end end diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 4f99c9df9..d6c899bbe 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -1,6 +1,12 @@ -
<%= link_to debate.title, debate %>
<%= debate.description %>
-Creado el: <%= l debate.created_at.to_date %>
+ ++ Creado el: <%= l debate.created_at.to_date %> + por: <%= debate.author.name %> +
+ +<%= render 'shared/tags', debate: debate %>
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 %> - <% if action_name == 'new' %> +<%= @debate.title %>
<%= @debate.description %>
-Creado el: <%= l @debate.created_at.to_date %>
++ Creado el: <%= l @debate.created_at.to_date %> + por: <%= @debate.author.name %> +
<%= notice %>
<%= alert %>
+ + <%= render 'devise/menu/login_items' %> + <%= yield %>