Ruby rails - ajax form_tag没有进行ajax调用

时间:2012-04-18 10:51:10

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

我有一个适用于html的表单,我正在尝试将其转换为ajax。这是我的代码,我认为问题是我的表单没有提交ajax请求,它仍然发送正常的html请求。我用部分渲染了一个新页面(item / create)。怎么解决这个问题?

<%= form_tag ( :action => :create, :remote => true, :method => :post ) do %>
... #stuff
<% end %>

控制器 -

def create
...
    respond_to do |format|
            format.html { render :partial => 'view_item', :item_num => @t[:item_num], :flag => "new" }
            format.js
            end
end

JS -

# cat view.js.erb
$('#item').html(<%= (render :partial => 'view_item').to_json.html_safe %>); #I have "item" div in my view

记录 -

Started POST "/item/create" for 10.10.23.12 at 2012-04-18 06:41:23 -0400
Processing by ItemController#create as HTML
  Parameters: {"utf8"=>"â", "authenticity_token"=>"GRNJAx2ePzRIOaJjr2w4F6WwueRq7FL9tIDaKtIPZSQ=", 
.......#long log here
"
   (0.1ms)  COMMIT
  Rendered item/_view_item.html.erb (1.6ms)
Completed 200 OK in 3261ms (Views: 2.4ms | ActiveRecord: 4.1ms)

0 个答案:

没有答案