获取ActionView :: MissingTemplate

时间:2016-01-26 23:16:29

标签: ruby-on-rails ruby

我有一个名为def createCustomer的方法,所以我在文件夹名charge内创建了一个名为createCustomer的.html.erb文件,该文件是控制器的名称。此charge文件夹位于views文件夹下。

我在日志中得到这个

ActionView::MissingTemplate (Missing template charge/createCustomer, application/createCustomer with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: 2016-01-26T23:00:34.324498+00:00 app[web.1]:   * "/app/app/views"

1 个答案:

答案 0 :(得分:0)

要添加到评论中,您需要将自己与Rails基础架构(convention over configuration)等同起来:

以下是如何构建的:

# config/routes.rb
resources :customers #-> url.com/customers/new

# app/controllers/customers_controller.rb
class CustomersController < ApplicationController
   def new
      @customer = Customer.new
   end

   def create
      @customer = Customer.new customer_params
      redirect_to @customer if @customer.save
   end

   private

   def customer_params
      params.require(:customer).permit(...)
   end
end

# app/views/customers/new.html.erb
<%= form_for @customer do |f| %>
   ...