Skip to content

Instantly share code, notes, and snippets.

@rangerscience
Created May 5, 2011 22:34
Show Gist options
  • Save rangerscience/958117 to your computer and use it in GitHub Desktop.
Save rangerscience/958117 to your computer and use it in GitHub Desktop.
= form_for @office, :remote => true do |f|
-if @office.errors.any?
#error_explanation
%h2= "#{pluralize(@office.errors.count, "error")} prohibited this office from being saved:"
%ul
- @office.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :title
= f.text_field :title
.field
= f.label "state_id"
= collection_select(:state, :state_id, State.all, :id, :name)
.field
= f.label "county_id"
= collection_select(:county, :county_id, State.all, :id, :name)
.field
= f.label "city_id"
= collection_select(:city, :city_id, City.all, :id, :name)
.actions
= f.submit 'Save'
:javascript
jQuery(function(){
$("#state_state_id").change(function() {
$.post(<%= get_counties_url(:id => state.id) %>, function(data)
{ $.("city_city_id").html(data);
});
});
});
@rangerscience
Copy link
Author

def get_counties
@counties = County.find_by_place_id(params[:id])
render :inline => "= collection_select(:county, :county_id, @counties, :id, :name)", :content_type => "haml"
end

@rangerscience
Copy link
Author

match 'states/:id/get_counties' => 'states#get_counties', :as => :get_counties

@krainboltgreene
Copy link

$.post(<%= get_counties_url(:id => state.id) %>, function(data)

$.post(#{ get_counties_url(:id => state.id) }, function(data)

@krainboltgreene
Copy link

:javascript
jQuery(function(){
  $("#state_state_id").change(function() {
    var state_id = this.val();
    $.post('/state/' + state_id + '/get_counties', function(data)
      { $.("city_city_id").html(data);
    });
  });
});

@krainboltgreene
Copy link

def get_counties
   logger.info 'id:' + params[:id]
    # @counties = County.find_by_place_id(params[:id])
    # render :inline => "= collection_select(:county, :county_id, @counties, :id, :name)", :content_type => "haml"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment