Ich erstelle ein Formular für die Datenerfassung, das ich mit Polymer zu implementieren versuche.Fehlende Vorlage zum Erstellen. Interner Serverfehler - Speichern des Polymerformulars in DB
Ich habe versucht, das Senden zu implementieren, indem Sie eine Schaltfläche an einige JQuery binden, um das Formular zu senden, und auch Rails eigene Formularhilfe zu verwenden, aber ohne Erfolg. Die Fehlermeldungen sind ziemlich vage und haben mir nicht viel Einblick in das Problem gegeben.
Von dem, was ich verstehe, ist der Grund, der versucht, eine create.html.erb zu rendern, weil für den Fall, dass die Aktion fehlschlägt, versucht wird, eine Ansicht mit einem Namen mit dieser Aktion zu rendern. Ich habe auch Redirect zu der/new-Aktion für den Fall enthalten, dass das Speichern in der Datenbank in der Erstellungsaktion fehlschlägt, dies scheint jedoch nicht zu funktionieren.
Ich habe auch die Struktur meiner Parameter Anzahl der Male überprüft und sie scheinen im richtigen Format zu sein.
Kann jemand sehen, wo es hier falsch läuft?
Server-Protokoll:
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"
):
Neue Ansicht:
<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'}
]);
});
});
Controller:
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
Wenn das Monument erfolgreich erstellt wurde, was möchten Sie mit Ihrer App erreichen? – niceman
Es ist eine dumme Form, die wirklich auf mobile Geräte mit einigen zusätzlichen Dienstprogrammen ausgerichtet ist, die ich mir vorstelle, wenn mehr Anforderungen entstehen. Danach muss ich einen Konnektor schreiben, damit die Daten an verschiedene Ziele exportiert werden können. – CrazyMyBeat