Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 缺少用于创建的模板。内部服务器错误-聚合表单保存到数据库_Javascript_Ruby On Rails_Forms_Post_Polymer - Fatal编程技术网

Javascript 缺少用于创建的模板。内部服务器错误-聚合表单保存到数据库

Javascript 缺少用于创建的模板。内部服务器错误-聚合表单保存到数据库,javascript,ruby-on-rails,forms,post,polymer,Javascript,Ruby On Rails,Forms,Post,Polymer,我正在创建一个用于数据收集的表单,我正在尝试使用Polymer实现该表单 我已经尝试通过将一个按钮绑定到某个JQuery来实现提交,以提交表单,并使用Rails自己的提交表单帮助器,但没有效果。 错误消息非常模糊,没有让我深入了解问题 据我所知,它试图呈现create.html.erb的原因是,如果操作失败,它将尝试呈现名称与该操作匹配的视图。我还包括了在create操作中保存到DB失败时重定向到/new操作,但是这似乎不起作用 我还多次检查了参数的结构,它们的格式似乎正确 有人能看出哪里出了问

我正在创建一个用于数据收集的表单,我正在尝试使用Polymer实现该表单

我已经尝试通过将一个按钮绑定到某个JQuery来实现提交,以提交表单,并使用Rails自己的提交表单帮助器,但没有效果。 错误消息非常模糊,没有让我深入了解问题

据我所知,它试图呈现create.html.erb的原因是,如果操作失败,它将尝试呈现名称与该操作匹配的视图。我还包括了在create操作中保存到DB失败时重定向到/new操作,但是这似乎不起作用

我还多次检查了参数的结构,它们的格式似乎正确

有人能看出哪里出了问题吗

服务器日志:

Started POST "/monuments" for ::1 at 2016-04-18 15:16:06 +0100
Processing by MonumentsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"DKt++BX5141UhbH2jyNmUDXWj24PoPxa2UGVQFubTAxbjRPhhwTHvnAxtVQgdptM9jlu+0CKMX6HeUkCJo1saA==", 
   "monument"=>{"visit_date"=>"2016-04-18", 
   "site_name"=>"Site 1", 
   "parish"=>"Parish 1", 
   "designation_no"=>"1010101", 
   "her_no"=>"1100110", 
   "site_type"=>"Title 1", 
   "condition"=>"Cond 2", 
   "description"=>"Descriptive text here", 
   "current_management"=>"curr 3", 
   "condition_trend"=>"Some trend", 
   "trend_notes"=>"Notes on trend here", 
   "vulnerability"=>"Vul 4"}, "commit"=>"Create Monument"}
       (0.2ms)  BEGIN
      SQL (1.7ms)  INSERT INTO "monuments" ("site_name", "visit_date", "parish", "designation_no", "her_no", "site_type", "description", "condition", "current_management", "condition_trend", "trend_notes", "vulnerability") VALUES (           ) RETURNING "id"  [["site_name", "Site 1"], ["visit_date", "2016-04-18"], ["parish", "Parish 1"], ["designation_no", 1010101], ["her_no", 1100110], ["site_type", "Title 1"], ["description", "Descriptive text here"], ["condition", "Cond 2"], ["current_management", "curr 3"], ["condition_trend", "Some trend"], ["trend_notes", "Notes on trend here"], ["vulnerability", "Vul 4"]]
       (1.3ms)  COMMIT
    Completed 500 Internal Server Error in 78ms

    ActionView::MissingTemplate (Missing template monuments/create, application/create with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
      * "/Users/user/Development/recorder/app/views"
):
新观点:

<div class="container">
  <%= form_for @monument, url: {action: "create"}, html: {is: "iron-form"} do |f| %>
  <form is="iron-form" id="form" method="post" action="/monuments">
  <div class="row">
    <div class="col-xs-10 col-xs-offset-1">
      <google-map disable-default-ui zoom="15">
        <google-map-marker></google-map-marker>
      </google-map>
    </div>
    <div class="col-xs-10 col-xs-offset-1">

      <template is="dom-bind" id="scope">
        <section>
          <h3>{{dateFormat(date, 'LL')}}</h3>
          <input type="hidden" name="monument[visit_date]" value="{{dateFormat(date, 'YYYY-MM-DD')}}" readonly="readonly">
          <paper-button class="btn" on-tap="showDialog" raised>Change Date</paper-button>
          <paper-dialog id="dialog" class="paper-date-picker-dialog" modal on-iron-overlay-closed="dismissDialog">
            <paper-date-picker id="picker"></paper-date-picker>
            <div class="buttons">
              <paper-button dialog-dismiss>Cancel</paper-button>
              <paper-button dialog-confirm>OK</paper-button>
            </div>
          </paper-dialog>
        </section>
      </template>

    </div>
    <div class="col-xs-10 col-xs-offset-1">

      <paper-input label="Site name" name="monument[site_name]"></paper-input>
      <paper-input label="Parish" name="monument[parish]"></paper-input>
      <paper-input label="Designation number" name="monument[designation_no]" type="number"></paper-input>
      <paper-input label="HER Number" name="monument[her_no]" type="number"></paper-input>

      <template id="site" is="dom-bind">
        <paper-dropdown-menu label="Site type" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
          <paper-listbox class="dropdown-content" attr-for-selected="value" selected="{{item}}">
            <template is="dom-repeat" items="{{types}}" as="type">
              <paper-item value="[[type.name]]">[[type.name]]</paper-item>
            </template>
          </paper-listbox>
        </paper-dropdown-menu>
        <input is="iron-input" type="hidden" name="monument[site_type]" value="[[selectedItem.value]]">
      </template>      

      <template id="cond" is="dom-bind">
        <paper-dropdown-menu label="Condition" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
          <paper-listbox class="dropdown-content" attr-for-selected="value" selected="{{item}}">
            <template is="dom-repeat" items="{{conditions}}" as="condition">
              <paper-item value="[[condition.name]]">[[condition.name]]</paper-item>
            </template>
          </paper-listbox>
        </paper-dropdown-menu>
        <input is="iron-input" type="hidden" name="monument[condition]" value="[[selectedItem.value]]">
      </template>      

      <paper-input id="desc" label="Description" name="monument[description]"></paper-input>

      <template id="curr-mgmt" is="dom-bind">
        <paper-dropdown-menu label="Current Management" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
          <paper-listbox class="dropdown-content" attr-for-selected="value" selected="{{item}}">
            <template is="dom-repeat" items="{{types}}" as="type">
              <paper-item value="[[type.name]]">[[type.name]]</paper-item>
            </template>
          </paper-listbox>
        </paper-dropdown-menu>
        <input is="iron-input" type="hidden" name="monument[current_management]" value="[[selectedItem.value]]">
      </template> 

      <paper-input label="Condition trend" name="monument[condition_trend]"></paper-input>

      <paper-input label="Trend notes" name="monument[trend_notes]"></paper-input>

      <template id="vulnerability" is="dom-bind">
        <paper-dropdown-menu label="Vulnerability" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
          <paper-listbox class="dropdown-content" attr-for-selected="value" selected="{{item}}">
            <template is="dom-repeat" items="{{types}}" as="type">
              <paper-item value="[[type.name]]">[[type.name]]</paper-item>
            </template>
          </paper-listbox>
        </paper-dropdown-menu>
        <input is="iron-input" type="hidden" name="monument[vulnerability]" value="[[selectedItem.value]]">
      </template>   

    </div>
  </div>
  <%= f.submit %>
  <% end %>
</div>
控制器:

class MonumentsController < ApplicationController

  def new
    @monument = Monument.new 
  end

  def create
    @monument = Monument.new(monument_params)

    if @monument.save
      flash[:success] = "Monument created successfully!"
    else
      flash[:error] = "Failed to create monument entry!"
      render "monuments/new"
    end
  end

  private

    def monument_params
      params.require(:monument).permit(:site_name, :visit_date, 
        :parish, :designation_no, :her_no, :site_type, :description,
        :condition, :current_management, :condition_trend, :trend_notes,
        :vulnerability
        )
    end
end
类纪念碑控制器
问题在于:

if(monument.save)
   flash[:success] = "Monument created successfully!"
   //nothing
else
   flash[:error] = "Failed to create monument entry!"
   render "monuments/new"
end
正好在
//nothing
部分

当控制器中的某个动作退出而不调用redirect或render rails时,假定您希望以与动作名称相同的名称呈现视图,例如,如果您有动作名称
hello
,并且该动作退出而不调用render或redirect,则将呈现视图
hello.erb.html
,在您的例子中,操作名称是
create
,因此它查找view
create.erb.html

我假设如果纪念碑被成功保存,您希望重定向到另一个页面,如果是这样,那么在
nothing
部分调用
redirect\u to
,在那里您希望重定向


如果你想做另一件事(可能你想呈现json响应等),然后调用render with anything,如果你想退出而不呈现任何内容,那么你可以编写
render nothing:true
,或者使用
head
方法生成没有内容的HTTP头。

问题在于:

if(monument.save)
   flash[:success] = "Monument created successfully!"
   //nothing
else
   flash[:error] = "Failed to create monument entry!"
   render "monuments/new"
end
正好在
//nothing
部分

当控制器中的某个动作退出而不调用redirect或render rails时,假定您希望以与动作名称相同的名称呈现视图,例如,如果您有动作名称
hello
,并且该动作退出而不调用render或redirect,则将呈现视图
hello.erb.html
,在您的例子中,操作名称是
create
,因此它查找view
create.erb.html

我假设如果纪念碑被成功保存,您希望重定向到另一个页面,如果是这样,那么在
nothing
部分调用
redirect\u to
,在那里您希望重定向


如果你想做另一件事(可能你想呈现json响应或其他),然后调用render with anything,如果你想退出而不呈现任何内容,那么你可以编写
render nothing:true
或使用
head
方法生成没有内容的HTTP头。

如果成功创建纪念碑,你想让你的应用程序做什么?这是一种愚蠢的形式,我想随着更多需求的出现,它将被锁定在带有附加实用程序的移动设备上。在此之后,我需要编写一个连接器,以便将数据导出到各个目的地。如果monument成功创建,您希望您的应用程序做什么?这是一个愚蠢的表单,它将针对移动设备,并附带一些附加的实用程序,我想随着更多需求的出现。在此之后,我需要编写一个连接器,以便将数据导出到各个目的地。这样一个简单的疏忽就解决了这个问题。谢谢你的帮助!正如我在问题中提到的,我读过Rails这样做的文章,但我没有意识到成功和失败也是如此。。。再说一遍,为什么不呢?谢谢这么简单的疏忽就解决了。谢谢你的帮助!正如我在问题中提到的,我读过Rails这样做的文章,但我没有意识到成功和失败也是如此。。。再说一遍,为什么不呢?谢谢