Hi, after saying this you will hate me, but i''ve changed an url which takes not the id but the nick. Something like /users/mix/comments everything works fine, just for a "little" problem, when i create the link with link_to or the paginate method it lowercase the controller string, so if i pass it something like :controller => "/users/#{@user.nick}/comments", :action => :index it will lowercase the nick, and if the nick is eg MiX it won''t find any user with mix. How can i solve this with have the nick as is? with link_to it can be solved without pass {:controller.... } but "/users/#{@user.nick}/comments", it works, but the problem stays with the paginate url, it doesn''t accept that Or another solution would be accept any kind of nick case insensitive, but i think that this would charge more the search in the db, and anyway it''s better to show the nick as the user has written it Thanks -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
stephen.celis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-27 14:35 UTC
Re: Case sensitive url and link_to... help
It shouldn''t be case-sensitive. User.find_by_username(params[:user_id]) should return the user. On Oct 27, 6:28 am, Mix Mix <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, after saying this you will hate me, but i''ve changed an url which > takes not the id but the nick. Something like /users/mix/comments > everything works fine, just for a "little" problem, when i create the > link with link_to or the paginate method it lowercase the controller > string, so if i pass it something like :controller => > "/users...-egtFW/fnoaZaa/9Udqfwiw@public.gmane.org}/comments", :action => :index it will lowercase the > nick, and if the nick is eg MiX it won''t find any user with mix. > How can i solve this with have the nick as is? with link_to it can be > solved without pass {:controller.... } but > "/users...-egtFW/fnoaZaa/9Udqfwiw@public.gmane.org}/comments", it works, but the problem stays with > the paginate url, it doesn''t accept that > Or another solution would be accept any kind of nick case insensitive, > but i think that this would charge more the search in the db, and anyway > it''s better to show the nick as the user has written it > Thanks > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
stephen.celis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> It shouldn''t be case-sensitive. > > User.find_by_username(params[:user_id]) should return the user.the problem is that find_by_username is case sensitive, if i''ve a user "Mix", if i find_by_username(''mix'') it won''t be found -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I know this isn''t exactly what you want, but I find it a nice go between often times, and you don''t need to hack everything up to make it work. I would pass the id as well as the username. You can do that by setting the method to_param in the model file for whatever model you want to preform this on, in your case, the user model. # user.rb def to_param "#{id}-#{username}" end The cool thing about to_param, is that you don''t have to change any of your link_to methods, or .find methods normally. If you did this in the view: # index.rhtml link_to @user.username, {:action => "show", :id => @user} or if you are using restful routes: link_to @user.username, user_path(@user) Looks pretty normal right? The cool thing is that even though it looks that normal, when you hit the link in the browser, the url will look like this: "/users/12-billybob" And in your controllers, you can do a very basic: User.find(params[:id]) If you still want to use only the username, there are also ways to do that, but they are not as easy, lemme know. On Oct 27, 2007, at 11:02 AM, Mix Mix wrote:> > stephen.celis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> It shouldn''t be case-sensitive. >> >> User.find_by_username(params[:user_id]) should return the user. > > the problem is that find_by_username is case sensitive, if i''ve a user > "Mix", if i find_by_username(''mix'') it won''t be found > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I know this isn''t exactly what you want, but I find it a nice go between often times, and you don''t need to hack everything up to make it work. I would pass the id as well as the username. You can do that by setting the method to_param in the model file for whatever model you want to preform this on, in your case, the user model. # user.rb def to_param "#{id}-#{username}" end The cool thing about to_param, is that you don''t have to change any of your link_to methods, or .find methods normally. If you did this in the view: # index.rhtml link_to @user.username, {:action => "show", :id => @user} or if you are using restful routes: link_to @user.username, user_path(@user) Looks pretty normal right? The cool thing is that even though it looks that normal, when you hit the link in the browser, the url will look like this: "/users/12-billybob" And in your controllers, you can do a very basic: User.find(params[:id]) If you still want to use only the username, there are also ways to do that, but they are not as easy, lemme know. On Oct 27, 2007, at 11:02 AM, Mix Mix wrote:> > stephen.celis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> It shouldn''t be case-sensitive. >> >> User.find_by_username(params[:user_id]) should return the user. > > the problem is that find_by_username is case sensitive, if i''ve a user > "Mix", if i find_by_username(''mix'') it won''t be found > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2007-10-27 04:28:05 -0700, Mix Mix <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> said:> > Hi, after saying this you will hate me, but i''ve changed an url which > takes not the id but the nick. Something like /users/mix/comments > everything works fine, just for a "little" problem, when i create the > link with link_to or the paginate method it lowercase the controller > string, so if i pass it something like :controller => > "/users/#{@user.nick}/comments", :action => :index it will lowercase the > nick, and if the nick is eg MiX it won''t find any user with mix. > How can i solve this with have the nick as is? with link_to it can be > solved without pass {:controller.... } but > "/users/#{@user.nick}/comments", it works, but the problem stays with > the paginate url, it doesn''t accept that > Or another solution would be accept any kind of nick case insensitive, > but i think that this would charge more the search in the db, and anyway > it''s better to show the nick as the user has written it > ThanksWhy are you doing this:> :controller => "/users/#{@user.nick}/comments", > :action => :indexI don''t understand... you have a controller (or namespace) named for each user!? I suspect that''s just an error in your question... I''m surprised that it would be changing the case of your user.nick, but if there is in fact a problem with that, you could write your own find_by_insensitive_nick method to work around that. Have you tried using to_param for this? class User def to_param nick end end Then, if you''re using map.resources for the route: <%= link_to user_comments_path(@user) %> Or else: <%= link_to :controller => ''comments'', :user_id => @user, :action => ''index'' %> HTH, --Andrew Vit --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Swasey wrote:> > If you still want to use only the username, there are also ways to do > that, but they are not as easy, lemme know.Yep, i need to have just the username without the id :( Andrew Vit wrote:> > Why are you doing this: > >> :controller => "/users/#{@user.nick}/comments", >> :action => :index > > I don''t understand... you have a controller (or namespace) named for > each user!? I suspect that''s just an error in your question...Because i''ve it to show all the comments the user have written, then i''ve a /comments/id to show just that comment and a /product/id/comments to show all the product''s comments. I think it''s quite strange :)> > I''m surprised that it would be changing the case of your user.nick, but > if there is in fact a problem with that, you could write your own > find_by_insensitive_nick method to work around that. >Sorry the ignorance, but how can i search with a case insensitive? and with, is it possible that the performances will be lower, right ?> Have you tried using to_param for this?yes, but doesn''t work :( -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Solved, i simply use ferret, i''ve done a find_by_username which use ferret with an insensitive case search, and return the result. Everything now works perfectly :) -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you use MySQL you can simply set the collation of the username field to utf8_general_ci (ci = case insensitive) for the same result. On Oct 28, 5:41 pm, Mix Mix <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Solved, i simply use ferret, i''ve done a find_by_username which use > ferret with an insensitive case search, and return the result. > Everything now works perfectly :) > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---