diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 53545887e..718772015 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,6 +1,7 @@ class DebatesController < ApplicationController before_action :set_debate, only: [:show, :edit, :update] - + before_action :authenticate_user!, only: [:new, :create] + def index @debates = Debate.all end @@ -16,7 +17,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 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/models/debate.rb b/app/models/debate.rb index 5a11c02cb..aee0618da 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,8 +1,11 @@ class Debate < ActiveRecord::Base acts_as_commentable + 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 -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..637c0086c 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -1,6 +1,9 @@
<%= 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 %> +
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' %> + <% if @debate.new_record? %> <%= f.check_box :terms_of_service %> Acepto la política de privacidad y el aviso legal <% end %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 770be127a..1d3a8ddac 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -1,7 +1,10 @@<%= @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 %>