文章#中的Recaptcha :: RecaptchaError显示没有指定网站密钥

Bor*_*ris 2 ruby ruby-on-rails

我明白了:

"文章#中的Recaptcha :: RecaptchaError显示没有指定网站密钥."

我不明白我的错误在哪里.

的Gemfile:

gem 'dotenv-rails', :require => 'dotenv/rails-now'
gem "recaptcha", require: "recaptcha/rails"
Run Code Online (Sandbox Code Playgroud)

.ENV

export RECAPTCHA_PUBLIC_KEY = '*******************************'
export RECAPTCHA_PRIVATE_KEY = '*******************************'
Run Code Online (Sandbox Code Playgroud)

comments_controller.rb

class CommentsController < ApplicationController

    http_basic_authenticate_with name: "admin", password: "**************", only: :destroy

  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  def destroy
    @article = Article.find(params[:article_id])
    @comment = @article.comments.find(params[:id])
    @comment.destroy
    redirect_to article_path(@article)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end
Run Code Online (Sandbox Code Playgroud)

articles_controller.rb

class ArticlesController < ApplicationController

    http_basic_authenticate_with name: "admin", password: "**********", except: [:index, :show]

  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end

  def new
    @article = Article.new
  end

  def edit
    @article = Article.find(params[:id])
  end

  def create
    @article = Article.new(article_params)

    if @article.save
      redirect_to @article
    else
      render 'new'
    end
  end

  def update
    @article = Article.find(params[:id])

    if @article.update(article_params)
      redirect_to @article
    else
      render 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to articles_path
  end

  private
    def article_params
      params.require(:article).permit(:title, :text)
    end
end
Run Code Online (Sandbox Code Playgroud)

Sim*_*ime 8

看起来你使用这个gem,它指定你需要:

export RECAPTCHA_ SITE _KEY ='6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyy'

export RECAPTCHA_ SECRET _KEY ='6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'

当我关注你的链接时,你有

export RECAPTCHA_ PUBLIC _KEY = \'*******************************\'

export RECAPTCHA_ PRIVATE _KEY = \'*******************************\'