Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTHOMAS THOMPSON
4,275 PointsMissing template
ActionView::MissingTemplate: Missing template todo_items/#<TodoItem:0x007fa14a8fcc10>, application/#<TodoItem:0x007fa14a8fcc10> with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/Users/Admin 1/Documents/Test App/testapp/app/views"
I get this error. I did not get it before having to add it "displays an error with no content" do
4 Answers
Salman Akram
Courses Plus Student 40,065 PointsHi Thomas,
Gotcha!......now let's take closer on this failure message:
1) Adding todo items displays an error with no content
Failure/Error: click_button "Save"
ActionView::MissingTemplate:
Missing template todo_items/#<TodoItem:0x007fc87f9f9260>, application/#<TodoItem:0x007fc87f9f9260> with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/Admin 1/Documents/Test App/testapp/app/views"
# ./app/controllers/todo_items_controller.rb:19:in `create' <<<<--------------------
# ./spec/features/todo_items/create_spec.rb:27:in `block (2 levels) in <top (required)> <<<<<<-----------------
You will find something wrong in number #19 above inside TodoItemsController since there is no action on click button "Save". Then we found out render action without colon is missing, it should have "action*:*" and then ":new"
For example you wrote in todo_items_controller.rb:
render action:new
Should have action:
render action: :new
Hint: @8:46
Another issues you have is Deprecation Warnings both 20 and 21, let's get rid of it.
Put this snippet into your spec_helper.rb inside spec folder on the bottom before end
.
config.infer_spec_type_from_file_location!
Hope it will solve these issues.
Salman Akram
Courses Plus Student 40,065 PointsHi Thomas,
Okay there are various reasons that we may get errors message, so do you have file - new.html.erb under todo_items inside views? If yes, paste here.
Please also add all failure messages here along with todo_items_controller inside app/controllers and create_spec.rb inside spec/features/todo_items?
THOMAS THOMPSON
4,275 PointsHere is new.html.erb:
<%= form_for [@todo_list, @todo_item] do |form| %>
<% if @todo_item.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@todo_item.errors.count, "error") %> prohibited this todo item from being saved:</h2>
<ul>
<% @todo_item.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form.label :content %>
<%= form.text_field :content %>
<%= form.submit "Save" %>
<% end %>
Here is what I have under todo_items_controller.rb:
class TodoItemsController < ApplicationController
def index
@todo_list = TodoList.find(params[:todo_list_id])
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new
end
def create
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new(todo_item_params)
if @todo_item.save
flash[:success] = "Added todo list item."
redirect_to todo_list_todo_items_path
else
flash[:error] = "There was a problem adding that todo list item."
render action:new
end
end
private
def todo_item_params
params[:todo_item].permit(:content)
end
end
Here is the complete failure message:
TDMT-Mac-Pro:testapp Admin$ rspec --format=documentation spec/features/todo_items/create_spec.rb
Adding todo items
is successful with valid content
displays an error with no content (FAILED - 1)
Failures:
1) Adding todo items displays an error with no content
Failure/Error: click_button "Save"
ActionView::MissingTemplate:
Missing template todo_items/#<TodoItem:0x007fc87f9f9260>, application/#<TodoItem:0x007fc87f9f9260> with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/Admin 1/Documents/Test App/testapp/app/views"
# ./app/controllers/todo_items_controller.rb:19:in `create'
# ./spec/features/todo_items/create_spec.rb:27:in `block (2 levels) in <top (required)>'
Deprecation Warnings:
RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (
it
,before
,after
,let
,subject
, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts. - The current example is now exposed via
RSpec.current_example
, which is accessible from any context. -
If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c| c.expose_current_running_example_as :example end
(Called from /usr/local/lib/ruby/gems/2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (
it
,before
,after
,let
,subject
, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts. - The current example is now exposed via
RSpec.current_example
, which is accessible from any context. -
If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c| c.expose_current_running_example_as :example end
(Called from /usr/local/lib/ruby/gems/2.2.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
config.raise_errors_for_deprecations!
, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
2 deprecation warnings total
Finished in 0.40161 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/features/todo_items/create_spec.rb:23 # Adding todo items displays an error with no content
Randomized with seed 44794
THOMAS THOMPSON
4,275 PointsThat did it. Thank you.