缺少用于创建的模板.内部服务器错误-聚合物表单保存到数据库
Missing template for create. Internal Server Error - Polymer form save to DB
我正在创建一个用于数据收集的表单,我正试图使用Polymer实现该表单。
我尝试通过将按钮绑定到一些JQuery来提交表单,并使用Rails自己的提交表单助手来实现提交,但没有成功。错误信息非常模糊,没有让我深入了解问题。
据我所知,它试图呈现create.html.erb的原因是,如果操作失败,它将尝试呈现具有与该操作匹配的名称的视图。我还包括了在创建操作中保存到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>
Javascript:
$(window).bind("load", function() {
$('paper-menu-button').removeAttr('disabled');
});
HTMLImports.whenReady(function() {
var scope = Polymer.dom(document).querySelector('#scope');
var site = document.querySelector('#site');
var condition = document.querySelector('#cond');
var vulnerability = document.querySelector('#vulnerability');
var curr_management = document.querySelector('#curr-mgmt');
scope.dateFormat = function(date, format) {
return moment(date).format(format);
};
scope.dismissDialog = function(event) {
if (event.detail.confirmed) {
scope.date = scope.$.picker.date;
}
};
scope.showDialog = function() {
this.$.dialog.toggle();
};
document.addEventListener('WebComponentsReady', function() {
scope.date = new Date();
scope.showDialog();
site.set('types',[
{name:'Title 1'},
{name:'Title 2'},
{name:'Title 3'},
{name:'Title 4'},
{name:'Title 5'}
]);
condition.set('conditions',[
{name:'Cond 1'},
{name:'Cond 2'},
{name:'Cond 3'},
{name:'Cond 4'},
{name:'Cond 5'}
]);
vulnerability.set('types',[
{name:'Vul 1'},
{name:'Vul 2'},
{name:'Vul 3'},
{name:'Vul 4'},
{name:'Vul 5'}
]);
curr_management.set('types',[
{name:'curr 1'},
{name:'curr 2'},
{name:'curr 3'},
{name:'curr 4'},
{name:'curr 5'}
]);
});
});
控制器:
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
,因此它会查找视图create.erb.html
。
我假设如果纪念碑被成功保存,你想重定向到另一个页面,如果是这样,那么在nothing
部分调用redirect_to
,在那里你想重定向。
如果你想做另一件事(也许你想渲染json响应等),那么用你想要的应用程序调用render,如果你想退出而不渲染任何东西,那么也许你可以编写render nothing:true
或使用head
方法生成没有内容的HTTP头。
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- 缺少用于创建的模板.内部服务器错误-聚合物表单保存到数据库
- 聚合物元素css未显示-检查器中没有错误
- 聚合物给我“未捕获的语法错误:意外的令牌(”
- 硫化破坏了聚合物代码(未捕获的类型错误:未定义不是一个函数)
- 未捕获的类型错误纸张对话聚合物
- 学习聚合物,获取参考错误:聚合物未定义
- 收到错误"聚合物::属性:无法't解码数组为JSON"在聚合物中使用铁ajax
- 为什么我得到的不是函数?错误的generateRequest聚合物铁ajax
- 聚合物自定义元素javascript数据绑定错误与firebase
- 聚合物dom-重复错误解析数组内的对象
- 聚合物元素内部的Meteor.call()会导致错误
- 在元素上设置属性会给出错误“无法使用聚合物设置未定义的属性'..'”