2016-04-18 5 views
1

私はPolymerを使用して実装しようとしているデータ収集用のフォームを作成しています。作成用のテンプレートがありません。内部サーバーエラー - ポリマーフォームをDBに保存

私はフォームを送信するいくつかのJQueryにボタンをバインドし、またRails自身の送信フォームヘルパーを使用しても送信しないようにしました。 エラーメッセージは非常に曖昧で、問題について多くの洞察を与えていません。

私が理解するところでは、create.html.erbをレンダリングしようとする理由は、アクションが失敗した場合、そのアクションに一致する名前のビューをレンダリングしようとするためです。また、作成アクションのDBへの保存に失敗した場合でも/ newアクションへのリダイレクトは含まれていますが、これは動作していないようです。

私はまた、自分のパラメータの構造の回数をチェックして、正しいフォーマットであるように見えます。

ここでどこが間違っているのか誰にでも見られますか?

Serverログ:

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 
+0

記念碑が正常に作成された場合、あなたのアプリは何をしますか? – niceman

+0

これは実際には、より多くの要件が出現するにつれて私が想像しているいくつかの追加ユーティリティを搭載したモバイルデバイスをターゲットにしたダムフォームです。この後、データをさまざまな宛先にエクスポートできるように、コネクタを作成する必要があります。 – CrazyMyBeat

答えて

0

問題はここにある://nothingセクションで正確

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

コントローラ内のアクションがリダイレクトを呼び出さずに終了するか、レンダリング・レールは、アクション名と同じ名前のビューをレンダリングすると想定します。たとえば、アクション名がhelloでレンダリングまたはリダイレクトを終了せずに終了した場合ビューhello.erb.htmlがレンダリングされます。アクション名はcreateでしたので、ビューcreate.erb.htmlを探しました。

記念碑が正常に保存された場合は別のページにリダイレクトしたいと思っています。その場合はredirect_tonothingセクションにリダイレクトする場所を指定してください。

あなたが(多分あなたはJSONレスポンスやなどをレンダリングする)別の事をしたいなら、あなたは何をレンダリングせずに終了したい場合は、その後、多分あなたはrender nothing:trueを書いたりheadメソッドを使用することができ、アプリを好きでレンダリングを呼び出しますコンテンツなしでHTTPヘッダーを生成します。

+0

そのような単純な見落としは、それを解決しました。ご協力ありがとうございました!私は私の質問で言及したようにそれをしているRailsについて読んでいたが、成功と失敗については同じことが分かっていなかった。ありがとう! – CrazyMyBeat

+0

@CrazyMyBeatあなたは大歓迎です:) – niceman

関連する問題