What i have <th>Age</th> <th>name</th> <th>Sex</th> what i did <th><%= link_to ''Age'',:order_by => ''age'', :action => ''index''%></th> <th><%= link_to ''name'',:order_by => ''name'', :action => ''index''%></th> <th><%= link_to ''Sex'',:order_by => ''Sex'', :action => ''index''%></th> What i need when user Click On Age or name or sex records should be in that order as user clicked.if user clicked on age Twice Then record should reverse . that would be bonus . By default it Should Be As working now. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 April 2010 12:29, ashu <rajeevsharma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What i have ><snip>> What i need > when user Click On Age or name or sex records > should be in that order as user clicked.if user clicked on age Twice > Then record should reverse . that would be bonus . > By default it Should Be As working now. >OK, so given that this isn''t a free-coding forum or a homework-for-you forum, what do you need? Hints on how to do this? Do you have code you''ve tried that isn''t working? I''ll start you with hints and you can then try it yourself... 1) The :order_by in your link_to will come through in the params hash in your controller as params[:order_by] 2) You can use :order as an option to ActiveRecord find methods (along with "ASC" or "DESC" for ordering) 3) You''ll need to remember the current order if you want to toggle it on clicks (or have it as another parameter in your link_to), you can use the session[:whatever_you_want] = ... construct for that. People are always happy to help, but you can''t just say "I need..." Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Andy I did this A Lot. :order => "#{params[:order_by]} = 1" there is a Write Query Running in my logger But Nothing happens .i thinks there must be a previous Code Which making my code Disable.Leave I have to consult my Senior . any Ways thanks Again For the advice Which are More important for me About Manners Thanks A lot. On Wed, Apr 14, 2010 at 5:05 PM, Andy Jeffries <andyjeffries-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> On 14 April 2010 12:29, ashu <rajeevsharma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> What i have >> > > <snip> > > >> What i need >> when user Click On Age or name or sex records >> should be in that order as user clicked.if user clicked on age Twice >> Then record should reverse . that would be bonus . >> By default it Should Be As working now. >> > > OK, so given that this isn''t a free-coding forum or a homework-for-you > forum, what do you need? Hints on how to do this? Do you have code you''ve > tried that isn''t working? > > I''ll start you with hints and you can then try it yourself... > > 1) The :order_by in your link_to will come through in the params hash in > your controller as params[:order_by] > > 2) You can use :order as an option to ActiveRecord find methods (along with > "ASC" or "DESC" for ordering) > > 3) You''ll need to remember the current order if you want to toggle it on > clicks (or have it as another parameter in your link_to), you can use the > session[:whatever_you_want] = ... construct for that. > > People are always happy to help, but you can''t just say "I need..." > > Cheers, > > > Andy > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Thanks: Rajeev sharma -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > I did this A Lot. > > :order => "#{params[:order_by]} = 1" >This should probably be something more like: session[:order_direction] ||= "ASC" :order => "#{params[:order_by]} #{session[:order_direction]}" there is a Write Query Running in my logger But Nothing happens .i thinks> there must be a previous Code Which making my code Disable.OK> Leave I have to consult my Senior . > any Ways thanks Again For the advice Which are More important for me About > Manners > Thanks A lot. >I assume this is sarcasm, but it''s really hard to tell. Anyway, as I said I''m happy to help, but I need to know where you''re at/what the problem is (not just the requirement) and also need to feel valued that you''re not just using me/others here for free coding. Cheers, Andy -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.