简体   繁体   English

ActionView :: Template :: Error缺少部分视图

[英]ActionView::Template::Error Missing partial View

Need Help!!!! 需要帮忙!!!! I am new to Rails. 我是Rails的新手。 I tried many solution but could not able to solve this issue. 我尝试了许多解决方案,但无法解决此问题。 I used Simple form ,Cocoon and haml to handle nested form for "has_many :through" relation( Its many to many relation). 我使用简单表单,Cocoon和haml处理“ has_many:through”关系(它的多对多关系)的嵌套形式。 I want to save deals and menuitems that come from the db. 我想保存来自数据库的交易和菜单项。 but it can't render _deal_menuitem_fields.html.haml It says partial view is missing. 但无法渲染_deal_menuitem_fields.html.haml它表示缺少部分视图。

Thats my '_form.html.haml' file. 那就是我的“ _form.html.haml”文件。

.sidenav
= link_to "Dashboard", controller: "dashboard" , :action => "dashboard_manager"
= link_to "Restaurant", controller: "restaurants" , :action => "index"
= link_to "Branch", controller: "branches" , :action => "index"
= link_to "Menu Items", controller: "menuitems" , :action => "index"
= link_to "Deals", controller: "deals" , :action => "index"
= link_to "Orders", controller: "dashboard" , :action => "dashboard_manager"
= link_to "User", controller: "users" , :action => "index"
.logout_sidebar_button
    = link_to "Logout", destroy_user_session_path, method: :delete

.main
= simple_form_for @deal, html: {multipart: true} do |f|
    - if @deal.errors.any?
        #errors
            %p
                #{@deal.errors.count} Prevented this Deal from saving
            %ul
                -@deal.errors.full_messages.each do |msg| 
                    %li = msg
    .panel-body
        =f.association :restaurant, label_method: :restaurant_name, value_method: :id, include_blank: false
        = f.input :deal_name, input_html: {class:'form-control'}
        = f.input :deal_description, input_html: {class:'form-control'}
        = f.input :deal_price, input_html: {class:'form-control'}
        = f.input :deal_rating, input_html: {class:'form-control'}
        = f.input :deal_quantity, input_html: {class:'form-control'}
        = f.input :deal_preptime, hint: "Time Should be in this Format 'HH:MM:SS'" , input_html: {class:'form-control'}
        = f.input :image, input_html: {class:'form-control'}
        =f.simple_fields_for :deal_menuitems do |deal_menuitem|
            = render'deal_menuitem_fields', f: deal_menuitem
        = link_to_add_association 'Add an Item', f, :deal_menuitems
    =f.button :submit, class: "btn btn-primary"

    %br/

= link_to "Back", {:controller => 'deals' ,:action => 'index'}, class: "btn btn-default"

And thats my _deal_menuitem_fields.html.haml file. 那就是我的_deal_menuitem_fields.html.haml文件。

.nested-fields.deal-menuitem-fields
.form-inline
    .menuitem_from_list
        = f.association :menuitem, collection: Menuitem.order(:menuitem_name), prompt: 'Choose an Item', label: false
        = f.input :menuitem_name
    = link_to_add_association 'or create a new Item', f, :menuitem, class: 'add-tag'
    = link_to_remove_association f, class: 'remove-tag btn btn-default btn-xs' do
        .glyphicon.glyphicon-remove

That's my controller deals_controller.rb 那就是我的控制器Deals_controller.rb

class DealsController < ApplicationController
 before_action :find_deal, only: [:show, :edit, :update, :destroy]
 def index
   @deal = Deal.all.order("created_at DESC")
 end
 def show   
 end
 def new
   @deal = Deal.new
 end
 def create
  @deal = Deal.new(deal_params)
  if @deal.save
    redirect_to @deal, notice: "Successfully created New Deal"
  else
    render 'new'
  end
 end
def edit
end

def update
 if  @deal.update(deal_params)
    redirect_to @deal
 else
    render 'edit'
 end     
end

def destroy
  @deal.destroy
  redirect_to :controller => 'deals', :action => 'index', notice:  "Successfully deleted Deal"
end

private

 def deal_params
  params.require(:deal).permit(
  :restaurant_id ,:deal_name, :deal_description, :deal_price, :deal_rating, :deal_quantity, :deal_preptime, :image, 
  deal_menuitems_attributes: [:id , :_destroy ,:menuitem_id, menuitem_attributes: [:id, :_destroy, :menuitem_name]]
  )
 end

 def find_deal  
   @deal = Deal.find(params[:id])
 end
end

Thats log from my console.. 那是从我的控制台记录的..

ActionView::Template::Error (Missing partial deals/_menuitem_fields, application/_menuitem_fields with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder, :haml]}. Searched in:
 * "/home/niazi/Desktop/servemeerepo/ServeMe/app/views"
 * "/var/lib/gems/2.3.0/gems/devise-4.4.3/app/views"):
  2:    .form-inline
  3:        .menuitem_from_list
  4:            = f.input :menuitem
  5:        = link_to_add_association 'or create a new Item', f, :menuitem, class: 'add-tag'
  6:        = link_to_remove_association f, class: 'remove-tag btn btn-default btn-xs' do
  7:            .glyphicon.glyphicon-remove

thats My models 多数民众赞成在我的模特

class Deal < ApplicationRecord
  #Database RelationShip
    belongs_to :user, optional: true;
   belongs_to :restaurant;
    #belongs_to :branch;

#many to many
   has_many :deal_menuitems , inverse_of: :deal;
   has_many :menuitems, :through => :deal_menuitems, :class_name => 'deal_menuitem';

   has_many :deal_orders;
   has_many :orders , :through => :deal_orders;
   accepts_nested_attributes_for :menuitems;    
   accepts_nested_attributes_for :deal_menuitems, allow_destroy: true
   has_attached_file :image, styles: { medium: "200x200#" }
   validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
 end


class DealMenuitem < ApplicationRecord
  belongs_to :deal;
  belongs_to :menuitem;

  accepts_nested_attributes_for :menuitem, :reject_if => :all_blank
end

class Menuitem < ApplicationRecord
  #Database RelationShip
  belongs_to :user, optional: true;
  belongs_to :restaurant;
  has_one :category;

  #many to many 
  has_many :deal_menuitems, inverse_of: :menuitem;
  has_many :deals, :through => :deal_menuitems;

  has_many :menuitem_orders;
  has_many :orders ,:through => :menuitem_orders;

  has_attached_file :image, styles: { medium: "200x200#" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end

It may be a missing underscore in your partial name. 您的部分名称中可能缺少下划线。 Ensure there's a _ at the beginning of your partial's actual file name. 确保部分文件的实际文件名开头有一个_

EG: 例如:

deals/_menuitem_fields.html.haml . deals/_menuitem_fields.html.haml

You may have: 你可能有:

deals/menuitem_fields.html.haml <=== Note the missing underscore!!! deals/menuitem_fields.html.haml <===注意下划线!!!

First fix: 首先解决:

As the error states, you are missing app/view/deals/_menuitem_fields.html.haml (you mistakenly have _deals_menuitem_fields.html.haml ). 由于错误状态,您缺少了app/view/deals/_menuitem_fields.html.haml (错误地拥有_deals_menuitem_fields.html.haml )。 So, you'll need to create the _menuitem_fields.html.haml in the app/views/deals directory. 因此,您需要在app/views/deals目录中创建_menuitem_fields.html.haml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActionView :: MissingTemplate ::缺少模板-Java脚本部分 - ActionView::MissingTemplate :: Missing template - Java Script partial Rails 3上缺少ActionView :: Template :: Error - ActionView::Template::Error missing on Rails 3 ActionView :: Template :: Error(缺少部分引脚/引脚…+ will_paginate无限分页错误 - ActionView::Template::Error (Missing partial pins/pin… + will_paginate infinite pagination error ActionView::Template::Error(缺少部分视图/作业/_index with {:locale=&gt;[:en], :formats=&gt;[:html], :variants=&gt;[], - ActionView::Template::Error (Missing partial views/jobs/_index with {:locale=>[:en], :formats=>[:html], :variants=>[], 带有RoR的Heroku Deploy日志抱怨ActionView :: Template :: Error缺少部分布局/填充 - Heroku Deploy logs with RoR complaining ActionView::Template::Error Missing partial layouts/shim ActionView :: Template :: Error(缺少必需的:bucket选项) - ActionView::Template::Error (missing required :bucket option) 对于缺少的资产,Rails忽略ActionView :: Template :: Error - Rails ignore ActionView::Template::Error for missing assets 子域名+ ActionView :: Template ::错误(缺少要链接的主机!) - Subdomains + ActionView::Template::Error (Missing host to link to!) ActionView::Template::Error: 缺少要链接的主机 - ActionView::Template::Error: Missing host to link to ActionView :: MissingTemplate:缺少模板 - ActionView::MissingTemplate: Missing template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM