On Tue, Jul 10, 2012 at 4:42 PM, Scott Ribe <[email protected]>wrote:

> 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.
>
>
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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en-US.

Reply via email to