我有模型:创意,产品,产品。我试图添加产品的想法,通过项目的观点,想法的编辑。我的edit.html.erb -想法
<div id="items">
<%= render @idea.items %>
</div>
<div class="products">
<% @products.each do |p| %>
<%= p.title %><%= button_to '+', items_path(product_id: p.id, idea_id: @idea.id), remote: true %>
<% end %>
</div>我的物品控制器:
def create
product = Product.friendly.find(params[:product_id])
@item = @idea.add_product(product.id)
respond_to do |format|
if @item.save
format.js
end
end
endidea.rb
def add_product(product_id)
item = items.find_by(product_id: product_id)
if item
else
item = items.build(product_id: product_id)
end
item
end我的"create.js.erb“
$('#items').html("<%= escape_javascript render(@idea.items) %>");当我将"format.html {redirect_to :back}“放入def (items_controller)中时,一切正常,但没有AJAX=(
日志
在91毫秒内无法接受的406完成 行动主计长::未知数格式(行动主计长::未知数格式): app/控制器/items_Controller.rb:33:in‘`create’
帮帮我,伙计们。我搜索了整个互联网
发布于 2015-05-30 02:44:05
对于那些还在谷歌搜索的人来说..。它帮助我为routes.rb中的ajax操作指定默认值:routes.rb {format:'js'}。
post 'myaction' => 'mycontroller#myaction', defaults: { format: 'js' }https://stackoverflow.com/questions/28257924
复制相似问题