您好我有以下表格:
<%= 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"
我只有创建,销毁,更新和索引。我如何摆脱这个错误?
答案 0 :(得分: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