Ruby on Rails Wednesday, February 29, 2012

Hi all,

I have a link_to method in rails for each letter of the alphabet (early
days yet, will put it in a loop later). I have the same for a console on
another page and that one works fine but the one on my page for the
letters does not.

I have the following in my model:

def index
user_relation = case params[:username].present?
when true then User.where(:username => params[:username])
else User
end

@users = user_relation.paginate :page=>params[:page], :order =>
'created_at desc', :per_page => 10
end

and this is an example in my index:

<%= link_to 'A', users_path(:username => 'A'), {:style=>'color:#FFFFFF',
:class => "tabel-3"}%>

Now if I click on A it does not return any results despite there being
many users with the letter A but if I was to for example put in the
brackets the name AdrianShaw (one of the users in my database) and click
A it would return that exact user. What it seems to be doing is search
but only for exact match results, anything less than the full word and
it does not return.

How would I go about doing this so that it gets all users with the first
letter A and so on?

Thanks
Christopher Jones

--
Posted via http://www.ruby-forum.com/.

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

No comments:

Post a Comment