fixing conflicts

This commit is contained in:
rgarcia
2015-07-27 23:29:32 +02:00
18 changed files with 115 additions and 23 deletions

View File

@@ -0,0 +1,9 @@
jQuery ->
toggle_comment = (id) ->
$("#js-comment-form-#{id}").toggle()
$('.js-add-comment-link').click ->
id = $(this).data().id
toggle_comment(id)
false

View File

@@ -1,4 +1,5 @@
class DebatesController < ApplicationController
include RecaptchaHelper
before_action :set_debate, only: [:show, :edit, :update]
before_action :authenticate_user!, except: [:show, :index]
before_action :validate_ownership, only: [:edit, :update]
@@ -24,8 +25,11 @@ class DebatesController < ApplicationController
def create
@debate = Debate.new(debate_params)
@debate.author = current_user
@debate.save
respond_with @debate
if verify_captcha? and @debate.save
redirect_to @debate, notice: t('flash.actions.create.notice', resource_name: 'Debate')
else
render :new
end
end
def update
@@ -47,4 +51,9 @@ class DebatesController < ApplicationController
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
end
def verify_captcha?
return true unless recaptcha_keys?
verify_recaptcha(model: @debate)
end
end

View File

@@ -0,0 +1,11 @@
module CommentsHelper
def comment_link_text(parent)
parent.class == Debate ? "Comentar" : "Responder"
end
def comment_button_text(parent)
parent.class == Debate ? "Publicar comentario" : "Publicar respuesta"
end
end

View File

@@ -0,0 +1,8 @@
module RecaptchaHelper
def recaptcha_keys?
Recaptcha.configuration.public_key.present? &&
Recaptcha.configuration.private_key.present?
end
end

View File

@@ -1,7 +1,11 @@
<%= form_for [@debate, Comment.new] do |f| %>
<%= f.text_area :body %>
<%= f.hidden_field :commentable_type, value: parent.class %>
<%= f.hidden_field :commentable_id, value: parent.id %>
<%= f.submit 'Publicar comentario', :class => "button radius" %>
<% end %>
<%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': parent.id} %>
<div id="js-comment-form-<%= parent.id %>" style="display:none">
<%= form_for [@debate, Comment.new] do |f| %>
<%= f.text_area :body %>
<%= f.hidden_field :commentable_type, value: parent.class %>
<%= f.hidden_field :commentable_id, value: parent.id %>
<%= f.submit comment_button_text(parent), :class => "button radius" %>
<% end %>
</div>

View File

@@ -30,6 +30,8 @@
Acepto la política de privacidad y el aviso legal
<% end %>
<%= render 'shared/captcha' %>
<div class="actions">
<%= f.submit %>
</div>

View File

@@ -5,16 +5,16 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "Participación" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/modernizr" %>
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<script src="https://www.google.com/recaptcha/api.js?hl=<%= I18n.locale %>"></script>
</head>
<body>
<body>
<%= render 'layouts/header' %>
<% if notice %>
<p class="alert-box success"><%= notice %></p>
<% end %>
@@ -22,11 +22,11 @@
<% if alert %>
<p class="alert-box success"><%= alert %></p>
<% end %>
<div class="row">
<div class="small-12 column">
<%= yield %>
</div>
</div>
</body>
</div>
</body>
</html>

View File

@@ -0,0 +1,3 @@
<% if recaptcha_keys? %>
<%= recaptcha_tags ajax: true, hl: I18n.locale %>
<% end %>

View File

@@ -1,3 +1,3 @@
<% if debate.tags.any? %>
<i class="fi-price-tag"></i> <%= tags(debate) %>
<i class="fi-price-tag"></i> <span class='tags'><%= tags(debate) %></span>
<% end %>