一:partial模版替换
$(document).on('change','.change_city',function(){
var $this = $(this),
district_name = $this.find('.text').text();
if (district_name != "") {
$.ajax({
url: "/inquiry/inquiries/change_city",
type: "get",
data: {
district_name: district_name
},
success: function(data){
$this.parents('.fields').find('.city').html(data);
$(document).find('.ui.dropdown').dropdown();
}
});
}
});
def change_city
@cities = City.ind_cities(params[:district_name])||[]
render :partial => "change_city"
end
<%= select_tag "contact[inquiries][city]", options_for_select(@cities), include_blank: "City", class: "ui compact dropdown" %>
二:选择内容替换
<%= f.select :province, options_for_select(City.ind_districts, company.province), include_blank: 'Select State' %>
<%= f.select :city, options_for_select({company.city => company.city}.compact || [], company.city), include_blank: 'Select City' %>
$("#state").change(function(){
$.ajax({
type: "get",
url: '<%= get_cities_path %>',
dataType: "json",
data: {state: $('#state').val()},
success: function(data){
$("#city").html('<option value="">City </option>');
$("#city").append(data.options);
var select_comboSelect = $(document).find('select');
if (select_comboSelect.length && select_comboSelect.length > 0) {
select_comboSelect.comboSelect();
}
}
});
});
def city
options = City.ind_cities(params[:q].to_s.strip).inject(""){|options_str, c| options_str += "<option value='#{c[0]}'>#{c[1]}</option>"}
render json: {options: options}
end
分享到:
相关推荐
ruby on rails 实例 practical rails social networking sites ruby on rails 第三章内容代码,我自己写进去的,导入数据可以直接用,developemnt阶段,test没有做
此外,Ruby的面向对象特性是其一大亮点,书中详细介绍了如何创建和使用类,以及如何利用Ruby的鸭子类型实现灵活的编程。 高级主题,如正则表达式,也在书中有所涉及,这些内容对提升开发者解决复杂问题的能力至关...
脚手架是rails非常省事的方法,一些简单的增删改查脚手架都能实现,省去了我们不必要的麻烦,那么怎么用rails的脚手架呢,今天来讲解一下。 .指定端口启动rails项目 代码如下:ruby script/server webrick -p 3000 0...
以水泥为基体材料,利用稀土发光材料、反光材料制备出水泥基发光材料(LuminescentCementitiousMate-rials,简称LCM),采用强度试验、荧光分光光度计、亮度计、ESEM等测试手段研究LCM的抗折和抗压强度、发光亮度和余辉...
This paper describes a set-up for static teat, of erasable phase transition disc mate-rials. It has a power density of more than 8mW/um2, light spot of 1um and variable exposuretime of 0.1 μs to 1 ms
These include a complete laboratory manual for installing, con guring, securing, and experimenting with many of the servers discussed in the text, PowerPoint notes, animation tuto- rials to ...
(新[共14])Web开发敏捷之道--应用Rails进行敏捷Web开part04.rar
Web开发敏捷之道--应用Rails进行敏捷Web开发(第2版).part19.rar
Web开发敏捷之道--应用Rails进行敏捷Web开发(第2版中文版