Method: RecordSelectHelper#record_select_observer
- Defined in:
- lib/record_select/helpers/record_select_helper.rb
#record_select_observer(options = {}) ⇒ Object
Assists with the creation of an observer for the :onchange option of the record_select_field method. Currently only supports building an Ajax.Request based on the id of the selected record.
options should be a hash with all the necessary options except :id. that parameter will be provided based on the selected record.
Question: if selecting users, what’s more likely?
/users/5/categories
/categories?user_id=5
100 101 102 103 104 105 106 |
# File 'lib/record_select/helpers/record_select_helper.rb', line 100 def record_select_observer( = {}) fn = "" fn << "function(id, value) {" fn << "var url = #{url_for(options[:url].merge(:id => ":id:")).to_json}.replace(/:id:/, id);" fn << "new Ajax.Request(url);" fn << "}" end |