Re: [Rails] Display by alphabetical letter.
On 19 February 2012 19:48, Christopher Jones <lists@ruby-forum.com> wrote:
> Hey all, so I have a table of games in my rails application. The table
> has many of records within in.
>
> What I wish to do is have at the top of the page a sort of link system
> like the following
>
> A | B | C | D | .................. | X | Y | Z |
>
> What I want to do is when you click on a letter it will then display
> each of the games by their alphabetical record.
>
> It will do this by searching the game_name column but only extracting
> those with the first letter not that of which it includes the letter
> anywhere in the name.
>
> How would I go about doing this. I have done search systems before but
> can only do one search for a page based on a column. I want it to be a
> search in which any letter can be clicked and then will link you to
> associated games.
Assuming it is the find itself that is the problem try something like
Games.where( "name LIKE ?", "#{params[:letter]}%" )
You can play with this in the rails console to get the syntax right.
Obviously in that case you would not use params, but just a letter.
Colin
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home