2012-04-08 30 views
5

Tôi nhận được lỗi sau khi tôi thử cài đặt Recaptcha trên ứng dụng Rails 3 của tôi. Tôi đã đặt thẻ recaptcha trong tệp _form của tôi (xem đính kèm bên dưới).Rails 3/Recaptcha cài đặt - Không xác định biến địa phương hoặc phương pháp `recaptcha_tags '

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 %> 

Bạn có thể vui lòng cho biết?


_FORM.HTML.ERB FILE

<%= 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 %> 

POSTS CONTROLLER

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 

Trả lời

9

tôi đã cố gắng để tái tạo lỗi của bạn, nhưng sau khi đi bộ qua các Readme tất cả mọi thứ làm việc tốt.

Bạn đã khởi động lại máy chủ chưa?

Các bước tôi đã làm:

  1. tạo phím api
  2. tạo config/initializers/recaptcha.rb với mã của bạn và chìa khóa của tôi
  3. thay đổi hình thức của tôi với <% = recaptcha_tags%>
  4. khởi động lại máy chủ, cho bộ khởi tạo đang được tải

đó là ... có lẽ chỉ cần thử một lần e thời gian.

+2

khởi động lại máy chủ đã hoạt động. Doh! Cảm ơn bạn!!! – hikmatyar

Các vấn đề liên quan