0

Webページ全体の更新を避けるために、AJAXを使用して保存されたデータを読み込もうとしています。rails cast Jquery Ajax video episode 136を見てきました。

レンダリングされたフォームにデータを保存すると、問題が発生します。保存ボタンをクリックしても何も起こりませんが、クロム開発者ツールでデバッグを行うと、エラーが見つかりましたActionView::MissingTemplate in Locations#create。場所は私のモデルであり、作成するアクションを作成します。

私は何時間もかけて何が悪いのかを見つけようとしましたが、何の結果もなくレールキャストを何度も何度も見ました。誰かが助けてくれたらお願いします。

これは、コントローラー ファイル locations_controller.rb です。

class LocationsController < ApplicationController

  def index
    @locations = Location.all
    @json = Location.all.to_gmaps4rails 
  end 

  def new
    @location = Location.new
  end

  def edit
    @location = Location.find(params[:id])
  end

  def create
    @location = Location.new(params[:location])
     respond_to do |format|
        format.html { redirect_to @location, notice: 'Location was successfully created.' }
        format.js   
    end
  end

def show
    @location = Location.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @location }
    end
  end
  def update
    @location = Location.find(params[:id])

    respond_to do |format|
      if @location.update_attributes(params[:location])
        format.html { redirect_to @location, notice: 'Location was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @location.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @location = Location.find(params[:id])
    @location.destroy

    respond_to do |format|
      format.html { redirect_to locations_url }
      format.json { head :no_content }
    end
  end
end

これはモデル ファイル location.rb です。

class Location < ActiveRecord::Base
  attr_accessible :address, :gmaps, :latitude, :longitude, :name
  validates_presence_of :name, :address

  acts_as_gmappable :check_process => false


  def gmaps4rails_address
    address
  end

   def gmaps4rails_infowindow  
  "<h1>#{self.name}</h1>"
  end

  def gmaps4rails_sidebar
   "<h4>#{name}</h4>" 
  end
end

new.js.erb ファイル

$('#new_link').hide().after('<%= j render("form") %>');

create.js.erb ファイル

$('#new_location').remove();
$('#new_link').show();
$('#allsites').empty().append('<%= j render(@location) %>'); 

index.html.erb

<%= gmaps("markers" => {"data" => @json}) %>  


<table>
  <tr>
    <th>Name</th>
    <th>Address</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @locations.each do |location| %>
  <tr>
    <td><%= location.name %></td>
    <td><%= location.address %></td>
    <td><%= link_to 'Show', location %></td>
    <td><%= link_to 'Edit', edit_location_path(location) %></td>
    <td><%= link_to 'Destroy', location, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
</table>
<div id="allsites">
//here I want to load all the data, ignore the table above
  </div>


<%= link_to 'New Location', new_location_path, id:"new_link", remote: true%>

<br />

また、:remote => trueフォームに追加されました

部分的な _form.html.erb ファイル

<%= form_for(@location, :remote => true) do |f| %>
  <% if @location.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</h2>

      <ul>
      <% @location.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :address %><br />
    <%= f.text_field :address %>
  </div>
  <div class="field">
    <%= f.label :latitude %><br />
    <%= f.text_field :latitude %>
  </div>
  <div class="field">
    <%= f.label :longitude %><br />
    <%= f.text_field :longitude %>
  </div>
  <div class="field">
    <%= f.label :gmaps %><br />
    <%= f.check_box :gmaps %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Rails 3.2.13 での作業これは私のソースですhttp://railscasts.com/episodes/136-jquery-ajax-revised

助けや提案は感謝されます。皆さん、良い一日をお過ごしください

編集:スクリーンショットを忘れてすみません HTML エラー 500 Chrome デバッグ ツール

テンプレートの欠落エラー

4

1 に答える 1