尽管remote_form重定向?

时间:2012-04-03 15:37:40

标签: ajax ruby-on-rails-3 remote-forms

我有一个远程表单来更新我的一个对象。但是,在更新之后,Rails重定向到另一个页面,基本上就好像这个表单根本不是远程的。我做错了什么?

从视图:

  <td id='translation-<%= base_text.id.to_s %>' class='editable'>
    <span class="translationstring"><%= @translation.content %></span>
    <%= form_for @translation, :remote => true, :html => { :id => ('translation-form-for_' + base_text.id.to_s) } do |f| %>
      <%= text_area(:translation, :content, :rows => 2) %><%= f.hidden_field(:base_text_id) %><%= f.hidden_field(:lang) %>
    <% end %>
  </td>

我有jQuery使用.submit()提交表单。然后控制器执行:

def update
@translation = Translation.find(params[:id])

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

我还尝试了在网上找到的服务器端的替代响应,没有变化:

format.js { render :js => @translation, :status => :updated, :layout => !request.xhr }

请指教。

编辑:这是我的服务器为电话所说的内容:

Started PUT "/translations/1" for 127.0.0.1 at 2012-04-04 09:45:49 +0200
Processing by TranslationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"WbYiaRgermr2T4wzTPX/ftBsfOB8+
pHCYmhDFJMUu9I=", "translation"=>{"content"=>"Testet Schlüssel wieder.", "base_t
ext_id"=>"1", "lang"=>"de"}, "id"=>"1"}
  ←[1m←[36mTranslation Load (1.0ms)←[0m  ←[1mSELECT `translations`.* FROM `trans
lations` WHERE `translations`.`id` = 1 LIMIT 1←[0m
  ←[1m←[35m (0.0ms)←[0m  BEGIN
  ←[1m←[36m (81.0ms)←[0m  ←[1mUPDATE `translations` SET `content` = 'Testet Schl
üssel wieder.', `updated_at` = '2012-04-04 07:45:49' WHERE `translations`.`id` =
 1←[0m
  ←[1m←[35m (38.0ms)←[0m  COMMIT
Redirected to http://localhost:3000/translations/1
Completed 302 Found in 133ms (ActiveRecord: 120.0ms)

1 个答案:

答案 0 :(得分:1)

找到解决方案:提供:format =&gt; :我的表格标签上的json。也许jquery_ujs没有做好自己的工作,尽管“破坏”链接工作正常......