Ruby on rails 如何在rails应用程序中发送xml请求
我的应用程序中有这个按钮Ruby on rails 如何在rails应用程序中发送xml请求,ruby-on-rails,xml,Ruby On Rails,Xml,我的应用程序中有这个按钮 <%= button_to t('.add_html'), :class => "line-item", :product => product.id %> 我的控制器创建操作 def创建 @购物车=当前购物车 product=product.findparams[:product\u id] @行\u item=@cart.add\u productproduct.id respond_to do |format| if
<%= button_to t('.add_html'), :class => "line-item", :product => product.id %>
我的控制器创建操作
def创建
@购物车=当前购物车
product=product.findparams[:product\u id]
@行\u item=@cart.add\u productproduct.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
我该怎么做?试试这个:
<%= button_to t('.add_html'), action: :create, format: :xml, :class => "line-item" %>
@user1478137,两者都应该起作用。我之所以编辑,是因为我不想根据您的控制器生成我暗示的路径。
<%= button_to t('.add_html'), action: :create, format: :xml, :class => "line-item" %>