Method: RecordSelectHelper#link_to_record_select

Defined in:
lib/record_select/helpers/record_select_helper.rb

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, options = {})
  options[:params] ||= {}
  options[:params].merge!(:controller => controller, :action => :browse)
  options[:onselect] = "function(id, label) {#{options[:onselect]}}" if options[:onselect]
  options[:html] ||= {}
  options[:html][:id] ||= "rs_#{rand(9999)}"

  assert_controller_responds(options[:params][:controller])

  html = link_to_function(name, '', options[: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