while trying to familiarize with using resources for planning routes, I encountered a weird error:
No template for interactive request
ShoppersController#index is missing a template for request formats: text/html
routes.rb
Rails.application.routes.draw do
resources :shoppers
end
shoppers_controller.rb
class ShoppersController < ApplicationController
def index
end
def create
@shopper = Shopper.new
end
end
shoppers.html.erb
<h1>Welcome Shoppers</h1>
Does anyone know how to solve this?
Thanks for all the feedbacks you share.
CodePudding user response:
It's because the name of your view is wrong. As the error you're getting says: 'Rails expects an action to render a template with the same name contained in a folder named after its controller'
So in your case, the structure needs to be:
- app
- controllers
- shoppers_controller.rb
- views
- shoppers
- index.html.erb
- new.html.erb
- shoppers
- controllers
CodePudding user response:
Create a view with the name of the action in the controller!