【发布时间】:2014-08-23 07:53:54
【问题描述】:
我是 ROR 的新开发人员。我使用带有事件更改的 ajax 将数据从 show.html.erb 中的 select_tag 发送到 def show ... end 中的控制器。我尝试发送数据,但我的脚本不起作用。下面是我的脚本:
<script type="text/javascript">
$('#cbo').change(function() {
$.ajax({
url: "/product_details/show",
type: "POST",
data: {"cbo_id" : $('#cbo').val()},
dataType: "html",
success: function(data) {
alert('successfully');
}
});
});
</script>
在product_details/show.html.erb中
<%= form_tag(product_detail_path, :method => "post") do %>
<%= select_tag "categories", options_from_collection_for_select(Category.all, :id, :category_name),:id => 'cbo' %>
<% end %>
def show
@getcbo = params[:cbo_id]
end
我认为 url: "/product_details/show" 可能是错误的。那么我如何使用 url 将数据发送到 def show ...结束于控制器? 。请帮我 !
【问题讨论】:
-
为你写答案 - 很多改变
-
你能帮我改一下吗?我想得到关于我的问题的答案
-
是的,这就是我为你写答案的原因,哈哈
-
好的,谢谢。我在等你的答复
标签: ruby-on-rails ruby