Merge branch 'master' into escoger_idioma_803
Conflicts: app/controllers/application_controller.rb
This commit is contained in:
@@ -21,4 +21,9 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
I18n.locale = session[:locale]
|
||||
end
|
||||
|
||||
def verify_captcha?(resource)
|
||||
return true unless recaptcha_keys?
|
||||
verify_recaptcha(model: resource)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class CommentsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_debate, :set_parent
|
||||
before_action :set_debate, :set_parent, only: :create
|
||||
respond_to :html, :js
|
||||
|
||||
def create
|
||||
@@ -10,6 +10,12 @@ class CommentsController < ApplicationController
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
def vote
|
||||
@comment = Comment.find(params[:id])
|
||||
@comment.vote_by(voter: current_user, vote: params[:value])
|
||||
respond_with @comment
|
||||
end
|
||||
|
||||
private
|
||||
def comment_params
|
||||
params.require(:comments).permit(:commentable_type, :commentable_id, :body)
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
class DebatesController < ApplicationController
|
||||
include RecaptchaHelper
|
||||
before_action :set_debate, only: [:show, :edit, :update]
|
||||
before_action :authenticate_user!, except: [:show, :index]
|
||||
include RecaptchaHelper
|
||||
before_action :set_debate, only: [:show, :edit, :update, :vote]
|
||||
before_action :authenticate_user!, except: [:index, :show]
|
||||
before_action :validate_ownership, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
if params[:tag]
|
||||
@debates = Debate.tagged_with(params[:tag])
|
||||
@debates = Debate.tagged_with(params[:tag]).order("created_at DESC")
|
||||
else
|
||||
@debates = Debate.all
|
||||
@debates = Debate.all.order("created_at DESC")
|
||||
end
|
||||
@featured_debates = @debates.to_a.shift(3)
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -25,7 +26,7 @@ class DebatesController < ApplicationController
|
||||
def create
|
||||
@debate = Debate.new(debate_params)
|
||||
@debate.author = current_user
|
||||
if verify_captcha? and @debate.save
|
||||
if verify_captcha?(@debate) and @debate.save
|
||||
redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate')
|
||||
else
|
||||
render :new
|
||||
@@ -37,6 +38,10 @@ class DebatesController < ApplicationController
|
||||
respond_with @debate
|
||||
end
|
||||
|
||||
def vote
|
||||
@debate.vote_by(voter: current_user, vote: params[:value])
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_debate
|
||||
@@ -50,10 +55,4 @@ class DebatesController < ApplicationController
|
||||
def validate_ownership
|
||||
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
|
||||
end
|
||||
|
||||
def verify_captcha?
|
||||
return true unless recaptcha_keys?
|
||||
verify_recaptcha(model: @debate)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
class RegistrationsController < Devise::RegistrationsController
|
||||
include RecaptchaHelper
|
||||
|
||||
def create
|
||||
if verify_recaptcha
|
||||
if verify_captcha?(resource)
|
||||
super
|
||||
else
|
||||
build_resource(sign_up_params)
|
||||
flash.now[:alert] = t('recaptcha.errors.verification_failed')
|
||||
render :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
class VotesController < ApplicationController
|
||||
before_action :set_debate
|
||||
before_action :authenticate_user!
|
||||
respond_to :html, :js
|
||||
|
||||
def create
|
||||
register_vote
|
||||
notice = @debate.vote_registered? ? I18n.t("votes.notice_thanks") : I18n.t("votes.notice_already_registered")
|
||||
respond_with @debate
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_debate
|
||||
@debate = Debate.find(params[:debate_id])
|
||||
end
|
||||
|
||||
def register_vote
|
||||
@debate.vote_by voter: current_user, vote: params[:value]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user