如何在rails app中发送xml请求

时间:2013-12-26 04:52:42

标签: ruby-on-rails xml

我的申请表中有这个按钮。

 <%= button_to t('.add_html'), :class => "line-item", :product => product.id %>

当有人点击按钮时,我想要执行控制器的创建动作的跟随行。

format.xml  { render :xml => @line_item,
                                 :status => :created, :location => @line_item }

我的控制器创建动作       def创建         @cart = current_cart         product = Product.find(params [:product_id])         @line_item = @ cart.add_product(product.id)

    respond_to do |format|
      if @line_item.save
        format.html { redirect_to(store_url) }
        format.js { @current_item = @line_item }
        format.xml  { render :xml => @line_item,
                             :status => :created, :location => @line_item }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @line_item.errors,
                             :status => :unprocessable_entity }
      end
    end
  end

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个:

<%= button_to t('.add_html'), action: :create, format: :xml, :class => "line-item" %>