Стимулирующий рефлекс перестал работать после установки certbot certiciate

У меня есть приложение для блога rails 6, и я использую optimulus_reflex, чтобы пытаться публиковать / отменять публикацию сообщений, а также комментариев. По умолчанию для параметров post.published и comment.published установлено значение false. У меня есть кнопки для публикации / отмены публикации и одобрения / отмены комментариев. Он работал нормально, тогда я попытался установить сертификаты ssl с помощью certbot, и он перестал работать. Не уверен, что это связано, потому что я полностью удалил certbot и сертификаты, но я все еще не могу заставить рефлексы снова работать.

Я использую каплю digitalocean с ubuntu 20.04

Мой код для страницы редактирования сообщения:

      <% if @post.published? %>
  <a href="#"
    class='btn btn-secondary btn-block'
    data-reflex='click->PublisherReflex#unpublish'
    data-post-id='<%= @post.id %>'>
    Unpublish
  </a>
<% else %>
  <a href="#"
    class='btn btn-dark btn-block'
    data-reflex='click->PublisherReflex#publish'
    data-post-id='<%= @post.id %>'>
    Publish
  </a>
<% end %>

Файл publisher_reflex.rb:

      class PublisherReflex < ApplicationReflex
  def publish 
    post = Post.find(element.dataset[:post_id])
    post.update(published: true, published_at: Time.now)
  end

  def unpublish 
    post = Post.find(element.dataset[:post_id])
    post.update(published: false, published_at: nil)
  end
end

Что касается комментариев, то это почти то же самое. Кнопки на кнопках частично:

      <% if comment.published? %>
  <a href="#"
    class='btn btn-secondary btn-block'
    data-reflex='click->ApproverReflex#unapprove'
    data-comment-id='<%= comment.id %>
    Unapprove
  </a>
<% else %>
  <a hrmodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      elsemodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end
        reject_unauthorized_connection
      emodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      imodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
     module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
     module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
     module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end else
        reject_unauthorized_connection
      end
    end
  end
end self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
     module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end else
        reject_unauthorized_connection
      end
    end
  end
end # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end
    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
       module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
       module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
       module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      emodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
endnd
    end
  end
end verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
endf verified_user = User.find_by(id: cookies.signed['user.id'])
       module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
endnd
    end
  end
end
    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      emodule ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
endnd
    end
  end
endef="#"
    class='btn btn-dark btn-block'
    data-reflex='click->ApproverReflex#approve'
    data-comment-id='<%= comment.id %>'>
    Approve
  </a>
<% end %>

Approver_reflex.rb:

      class ApproverReflex < ApplicationReflex
  def approve 
    comment = Comment.find(element.dataset[:comment_id])
    comment.update(published: true, published_at: Time.now)
  end

  def unapprove 
    comment = Comment.find(element.dataset[:comment_id])
    comment.update(published: false, published_at: nil)
  end
end

В сообщении, которое я нашел здесь, я попытался создать файл initializers / warder_cookies.rb:

      Warden::Manager.after_set_user do |user, auth, opts|
  scope = opts[:scope]
  auth.cookies.signed["#{scope}.id"] = user.id
  auth.cookies.signed["#{scope}.expires_at"] = 30.minutes.from_now
end

Warden::Manager.before_logout do |_user, auth, opts|
  scope = opts[:scope]
  auth.cookies.signed["#{scope}.id"] = nil
  auth.cookies.signed["#{scope}.expires_at"] = nil
end

И в сообщении говорилось, что нужно добавить следующий код, но не было файла, поэтому я поискал и добавил его в файл channels / connection.rb:

      module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      # rubocop:disable Lint/AssignmentInCondition
      if verified_user = User.find_by(id: cookies.signed['user.id'])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

Я не уверен, что это подходящее место для этого кода, но он работает на локальном хосте, но не работает в производственной среде.

0 ответов

Другие вопросы по тегам