>
> I am not sure that it is a good idea to have a variable with the same
> name as the method. At the least it could be confusing.
>
Yeah, not a good practice, will change it, thanks.
>From the log:
Started GET "/sub_categories/names?q=a" for 127.0.0.1 at 2013-03-15
09:45:40 -0400
Processing by SubCategoriesController#names as JSON
Parameters: {"q"=>"a"}
SubCategory Load (0.5ms) SELECT "sub_categories".* FROM "sub_categories"
WHERE (name LIKE '%%') LIMIT 10
Completed 200 OK in 3ms (Views: 0.3ms | ActiveRecord: 0.5ms)
>From the Twitter documentation but I'm a little fuzzy on what to change.
wildcard - The pattern in the remote URL that will be replaced with the
user's query when a request is made. Defaults to%QUERY.
On Friday, March 15, 2013 9:43:17 AM UTC-4, Colin Law wrote:
>
> On 15 March 2013 13:19, Anthony DeFreitas
> <[email protected]<javascript:>>
> wrote:
> > Ok, I made some progress. I know get results when I search but I'm
> getting
> > the entire array instead of results just for the letter typed. Here's my
> > Controller:
> >
> > def names
> > names = []
>
> I am not sure that it is a good idea to have a variable with the same
> name as the method. At the least it could be confusing.
>
> > all = SubCategory.where("name LIKE ?", "%#{params[:term]}%")
>
> What is params[:term] set to?
> If you look in the log you should be able to see the sql executed, what is
> it?
>
> Colin
>
> > all.each { |subc| names << subc.name }
> >
> > render json: names
> > end
> >
> > On Thursday, March 14, 2013 9:43:19 PM UTC-4, Anthony DeFreitas wrote:
> >>
> >> This relates to the new standalone typeahead that Twitter recently
> >> released, not the Bootstrap version, see Twitter Typeahead.js
> >>
> >> I'm trying to integrate this into a rails app to lookup sub-categories
> >> from the db and I'm having trouble trying to get it to work.
> >>
> >> I have a local version working with hard coded data that you can see
> here:
> >> http://jsfiddle.net/v7dJ4/1/embedded/result/
> >>
> >> In my rails version I get no errors in the console when I search.
> >>
> >> Here is my JS:
> >>
> >> $(document).ready(function() {
> >>
> >> $('input.typeahead').typeahead({
> >>
> >> name: 'names',
> >>
> >> prefetch: '/sub_categories/names.json',
> >>
> >> limit: 10
> >>
> >> });
> >>
> >> });
> >>
> >> If I navigate to http://jog.dev/sub_categories/names.json I get the
> valid
> >> json data so that part is working:
> >>
> >> [["Migrations","Controllers","Models","Associations","Views","Tests"]]
> >>
> >> I think my problem is with 'name'. In the docs:
> >> https://github.com/twitter/typeahead.js#datasets it mentions that name
> is
> >> the string that is used to identify the dataset. Do I need to inject
> this
> >> into the json?
> >>
> >> Any help much appreciated.
> >>
> >>
> >>
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > To post to this group, send email to
> > [email protected]<javascript:>.
>
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/rubyonrails-talk/-/2adxA4EBklQJ.
> >
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/22eSfp6lRroJ.
For more options, visit https://groups.google.com/groups/opt_out.