0

こんにちは私は次のフォームを持っています:

<%= form_for featured_content, :remote => true do |f| %>
                                <%= f.text_field :url, :value => featured_content.url, :class => "form_text_field ajaxSingle" %>
                                <%= button_tag "Update", :class=>'greystyle', :type=>"submit" %>
                            <% end %>

次のJSで:

    $('.ajaxSingle').live('keyup', function() {
  $(this).parents('form:first').submit();
});

これは、次のコントローラーのアクションになります。

  def update
    @fc = FeaturedContent.find(params[:id])
    @fc.update_attributes(params[:featured_content])
  end

これはすべて完璧に機能します。ただし、フィールドを更新するたびに、JavaScriptコンソールで次のエラーが発生します。

ActionView::MissingTemplate (Missing template featured_contents/update, application/update with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:builder, :erb, :coffee]}. Searched in:
  * "/Users/rordev/Code/RubyOnRails/Projects/EverythingEver/Dev/everythingever/app/views"

作成、破棄、更新、および索引付けしかありません。このエラーを取り除くにはどうすればよいですか?

4

1 に答える 1

2

Railsにajax呼び出し専用の応答を提供するように指示する必要があります。

def update
  @fc = FeaturedContent.find(params[:id])
  @fc.update_attributes(params[:featured_content])
  respond_to do |format|
    format.html
    format.js   { render :json => {:status => 'ok' } } #or any response you might find usefull
  end
end
于 2012-12-31T15:42:10.640 に答える