【问题标题】:Rails 3 / Recaptcha installation - Undefined local variable or method `recaptcha_tags'Rails 3 / Recaptcha 安装 - 未定义的局部变量或方法“recaptcha_tags”
【发布时间】:2012-04-08 06:36:52
【问题描述】:

当我尝试在我的 Rails 3 应用上安装 Recaptcha 时出现以下错误。我已在我的 _form 文件中放置了 recaptcha 标记(见下文)。

Showing /Users/fkhalid2008/loand/app/views/posts/_form.html.erb where line #20 raised:

undefined local variable or method `recaptcha_tags' for #<# <Class:0x12d4e1870>:0x12d4dac78>
Extracted source (around line #20):

17:   <div class="actions">
18:     <%= f.submit %>
19:   </div>
20:   <%= recaptcha_tags %>
21: <% end %>

您能建议吗?


_FORM.HTML.ERB 文件

<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
I am a <%= f.text_field :title %> getting married in <%= f.text_field :job %> in <%= f.text_field :location %>, and looking for a wedding photographer. My budget is <%= f.text_field :salary %>.
</div>
<div class="actions">
<%= f.submit %>
</div>
<%= recaptcha_tags %>
<% end %>

帖子控制器

def create
@post = Post.new(params[:post])

respond_to do |format|
if verify_recaptcha && @post.save
format.html { redirect_to :action=> "index"}
format.json { render :json => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.json { render :json => @post.errors, :status => :unprocessable_entity }
end
end
end

GEMFILE

source 'http://rubygems.org'

gem 'rails', '3.1.1'
gem "twitter-bootstrap-rails", "~> 2.0.1.0"
gem 'recaptcha', :require => 'recaptcha/rails'

group :production do
gem 'pg'
end

group :development, :test do
gem 'sqlite3'
end

gem 'json'

group :assets do
gem 'sass-rails',   '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

RECAPTCHA.RB

Recaptcha.configure do |config|
config.public_key  = '6LdR......'
config.private_key = '6LdR7.....'
end

【问题讨论】:

    标签: ruby-on-rails recaptcha


    【解决方案1】:

    我试图重现您的错误,但在通过Readme 之后一切正常。

    你重启服务器了吗?

    我做的步骤:

    1. 生成 api 密钥
    2. 使用您的代码和我的密钥创建了 config/initializers/recaptcha.rb
    3. 更改了我的表单
    4. 重启服务器,初始化器正在加载

    就是这样...也许再试一次。

    【讨论】:

      猜你喜欢
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多