Is there a cleaner way to build the url in the following snippet?
$(function() {
$(‘#name’).change(function() {
$.ajax({
url: “<%= url_for({action: ‘lookup’}) %>” + “?term=” + this.value,
…
}
})
})
})
Note that I should not use a hard-coded URL, because this app should be
deployed at a sub-URI using Passenger.
–
Scott R.
[email protected]
http://www.elevated-dev.com/
(303) 722-0567 voice
On Tue, Jul 10, 2012 at 4:42 PM, Scott R.
[email protected]wrote:
})
Note that I should not use a hard-coded URL, because this app should be
deployed at a sub-URI using Passenger.
As far as I understood, you want to do a request to the lookup action in
your controller.
I recently discovered this
select(object, method, choices, options = {}, html_options = {})
inside your html_options hash you can put something like this
{data: {remote: true, url: url_for(controller: “your controller (if
necessary)”, action: “lookup”)}}
so whenever you choose an option it will do an ajax request with the
selected value.
Then you just need a handler in that view, or just have a lookup.js.erb
file that handle the controller action
HTH
Javier Q.