Forum: Ruby on Rails Missing Template when testing with the Brain Buster Captcha partial

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ad16c39757df433d4a55c1a15fc3457a?d=identicon&s=25 Matt W. (Guest)
on 2009-06-07 06:23
(Received via mailing list)
When I run my functional tests, they throw an error with the following
message:

ActionView::TemplateError: Missing template /_captcha.erb in view path
app/views:test/vendor/plugins/brain_buster/views/brain_busters
    On line #23 of app/views/contacts/_form.html.erb

        20:     <%= f.label :message %><br />
        21:     <%= f.text_area :message %>
        22:   </div>
        23:   <%= render :partial => '/captcha' unless action_name ==
'edit' %>
        24:   <div><%= f.submit "Submit" %></div>
        25: <% end %>

        app/views/contacts/_form.html.erb:23
        app/views/contacts/_form.html.erb:1
        app/views/contacts/edit.html.erb:1
        app/controllers/contacts_controller.rb:41:in `update'
        functional/contacts_controller_test.rb:80:in
`__bind_1244348412_114'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:271:in `call'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:271:in `run_current_setup_blocks'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:270:in `each'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:270:in `run_current_setup_blocks'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:252:in `test: on PUT to :update with invalid
params should respond with success. '
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
        /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:
46:in `run_suite'
        /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:
67:in `start_mediator'
        /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:
41:in `start'
        /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:
29:in `run'
        /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
        /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
        /usr/local/lib/ruby/1.8/test/unit.rb:278
        functional/contacts_controller_test.rb:88


I've checked to make sure the partial is in the right location, it is
in this directory:

/vendor/plugins/brain_buster/views/brain_busters/_captcha.html.erb

Any ideas as to why the test can't find the partial? It works fine
when I test it manually (via the browser).
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-06-07 23:28
(Received via mailing list)
Take off the slash?

   <%= render :partial => 'captcha' unless action_name == 'edit' %>

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Ad16c39757df433d4a55c1a15fc3457a?d=identicon&s=25 Matt W. (Guest)
on 2009-06-08 01:07
(Received via mailing list)
Thanks, but unfortunately, that had no affect…have you ever run into
this kind of thing before?
Ad16c39757df433d4a55c1a15fc3457a?d=identicon&s=25 Matt W. (Guest)
on 2009-06-08 01:16
(Received via mailing list)
Just to experiment, I used this instead:

<%= render :partial => "#{RAILS_ROOT}/vendor/plugins/brain_buster/
views/brain_busters/captcha.html.erb" unless action_name == 'edit' %>

and now I get the following error:

ActionView::TemplateError: Called id for nil, which would mistakenly
be 4 -- if you really wanted the id of nil, use object_id
    On line #4 of vendor/plugins/brain_buster/views/brain_busters/
_captcha.html.erb

        1: <% unless captcha_passed? %>
        2:      <span id="brain_buster_captcha" class="<%= if
last_captcha_attempt_failed? then 'captcha_failed' end %>">
        3:
        4:              <%= hidden_field_tag :captcha_id, @captcha.id
%>
        5:
        6:              <label for="captcha_answer">
        7:                      Spam protection: <%= @captcha.question
%>

        vendor/plugins/brain_buster/views/brain_busters/
_captcha.html.erb:4
        app/views/contacts/_form.html.erb:23
        app/views/contacts/_form.html.erb:1
        app/views/contacts/edit.html.erb:1
        app/controllers/contacts_controller.rb:41:in `update'
        functional/contacts_controller_test.rb:80:in
`__bind_1244416417_125477'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:271:in `call'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:271:in `run_current_setup_blocks'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:270:in `each'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:270:in `run_current_setup_blocks'
        /usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/
lib/shoulda/context.rb:252:in `test: on PUT to :update with invalid
params should assign @contact with a kind of Contact. '
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
        /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
        /usr/local/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:
46:in `run_suite'
        /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:
67:in `start_mediator'
        /usr/local/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:
41:in `start'
        /usr/local/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:
29:in `run'
        /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
        /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
        /usr/local/lib/ruby/1.8/test/unit.rb:278
        functional/contacts_controller_test.rb:88

I feel like after that point I'm just chasing the white rabbit, seems
that once I figure out the initial problem, things should be okay.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-06-08 15:54
(Received via mailing list)
My original suggestion was based on the error message:

>>> ActionView::TemplateError: Missing template /_captcha.erb in view
>>> path
>>> app/views:test/vendor/plugins/brain_buster/views/brain_busters

The partial you called out was
  render :partial => '/captcha'

Your new error is clearly that the @captcha instance variable has no
value in the partial. Have you tried something like:

  render :partial => 'captcha', :object => @captcha

and then within your _captcha.html.erb template using a local variable:

  <%= hidden_field_tag :captcha_id, captcha.id %>

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Ad16c39757df433d4a55c1a15fc3457a?d=identicon&s=25 Matt W. (Guest)
on 2009-06-09 01:32
(Received via mailing list)
Sorry, I didn't mean to confuse. I'd say the first error…

>>> ActionView::TemplateError: Missing template /_captcha.erb in view
>>> path
>>> app/views:test/vendor/plugins/brain_buster/views/brain_busters

…is still the prominent one. I tried your suggestion and am getting
the same error. Do you have any other suggestions?

I appreciate you taking the time!

Matt
B5d0f22fb801b1da104f8ab647bad928?d=identicon&s=25 Kiminari H. (kiminari_h)
on 2010-11-24 07:56
I met the same problem and solved it.

> When I run my functional tests, they throw an error with the following
> message:
>
> ActionView::TemplateError: Missing template /_captcha.erb in view path
> app/views:test/vendor/plugins/brain_buster/views/brain_busters
>     On line #23 of app/views/contacts/_form.html.erb
>
>         20:     <%= f.label :message %><br />
>         21:     <%= f.text_area :message %>
>         22:   </div>
>         23:   <%= render :partial => '/captcha' unless action_name ==
> 'edit' %>
>         24:   <div><%= f.submit "Submit" %></div>
>         25: <% end %>
>

I changed single quotation to double quotation.
<%= render :partial => "captcha" %>
This topic is locked and can not be replied to.