Method: RecordSelectHelper#link_to_record_select
- Defined in:
- lib/record_select/helpers/record_select_helper.rb
#link_to_record_select(name, controller, options = {}) ⇒ Object
Adds a link on the page that toggles a RecordSelect widget from the given controller.
Options
onselect-
JavaScript code to handle selections client-side. This code has access to two variables: id, label. If the code returns false, the dialog will not close automatically.
params-
Extra URL parameters. If any parameter is a column name, the parameter will be used as a search term to filter the result set.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/record_select/helpers/record_select_helper.rb', line 7 def link_to_record_select(name, controller, = {}) [:params] ||= {} [:params].merge!(:controller => controller, :action => :browse) [:onselect] = "function(id, label) {#{options[:onselect]}}" if [:onselect] [:html] ||= {} [:html][:id] ||= "rs_#{rand(9999)}" assert_controller_responds([:params][:controller]) html = link_to_function(name, '', [:html]) html << javascript_tag("new RecordSelect.Dialog(#{options[:html][:id].to_json}, #{url_for(options[:params].merge(:escape => false)).to_json}, {onselect: #{options[:onselect] || ''}})") return html end |