I want to sort a collection of tasks based on their project name, but the project name is referenced thru project_id in the task table and belongs_to in the task-model. I can''t seem to find the proper way to use find(:all, :order => ?) correctly. How do I sort based on a joined table? 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 -~----------~----~----~----~------~----~------~--~---
you can do something like order="desc" -- 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 -~----------~----~----~----~------~----~------~--~---
Use the :include parameter of find to load the associated projects to allow you to sort eg Task.find(:all, :include => :project, :order => :project_name) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
eg Task.find(:all, :include => :project, :order => :project_name) It doesn''t work I''m afraid. At least not when using it in my context, which is: <% timeframe.tasks.find(:all, :order => ''project_id'').each do |@task| %> -- 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 Oct 10, 2007, at 9:42 AM, Gustav Stockholm wrote:> eg Task.find(:all, :include => :project, :order => :project_name) > > It doesn''t work I''m afraid. At least not when using it in my context, > which is: > > <% timeframe.tasks.find(:all, :order => ''project_id'').each do | > @task| %> > --<% timeframe.tasks.find(:all, :include => :project, :order => ''projects.name'').each do |task| %> Note that I''ve changed your block variable to a local rather than an instance variable. When you eager-load an associated model (:include => :project), you need to make sure that the sql fragment in the order option is valid which often means prepending the table name (particularly if the column name appears in more than one of the tables involved... or could in the future). -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> <% timeframe.tasks.find(:all, :include => :project, :order => > ''projects.name'').each do |task| %>It worked, thanks a million! However, I''m keeping the instance variable ''cause it''s the only way I can seem to get my checkboxed to show up as checked: <%= check_box ''task'', ''completed'', :onchange => remote_function( :url => { :action => ''toggle_completed'', :id => @task }, :with => "''id=#{@task.id}''" ) %> Any suggestions on why it doesn''t work with a local variable is much appreciated ;) Thanks again! -- 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 10 Oct 2007, at 16:22, Gustav Stockholm wrote:> >> <% timeframe.tasks.find(:all, :include => :project, :order => >> ''projects.name'').each do |task| %> > > It worked, thanks a million! However, I''m keeping the instance > variable > ''cause it''s the only way I can seem to get my checkboxed to show up as > checked: > > <%= check_box ''task'', ''completed'', :onchange => remote_function > ( :url => > { :action => ''toggle_completed'', :id => @task }, :with => > "''id=#{@task.id}''" ) %> > > Any suggestions on why it doesn''t work with a local variable is much > appreciated ;)check_box and its instance variable convention. Use form/fields_for or use check_box_tag Fred --~--~---------~--~----~------------~-------~--~----~ 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 Oct 10, 2007, at 11:32 AM, Frederick Cheung wrote:> On 10 Oct 2007, at 16:22, Gustav Stockholm wrote: >>> <% timeframe.tasks.find(:all, :include => :project, :order => >>> ''projects.name'').each do |task| %> >> >> It worked, thanks a million! However, I''m keeping the instance >> variable >> ''cause it''s the only way I can seem to get my checkboxed to show >> up as >> checked: >> >> <%= check_box ''task'', ''completed'', :onchange => remote_function >> ( :url => >> { :action => ''toggle_completed'', :id => @task }, :with => >> "''id=#{@task.id}''" ) %> >> >> Any suggestions on why it doesn''t work with a local variable is much >> appreciated ;) > > check_box and its instance variable convention. Use form/fields_for > or use check_box_tag > > Fred... which you can overcome by giving an :object option: <%= check_box(''task'', ''completed'', :object => task, :onchange => remote_function( :url => { :action => ''toggle_completed'', :id => task }, :with => "''id=#{task.id}''" )) %> Do you really need that :with option if the :url has the :id already? -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn wrote:> ... which you can overcome by giving an :object option: > > <%= check_box(''task'', ''completed'', :object => task, > :onchange => remote_function( > :url => { :action => ''toggle_completed'', :id => task }, > :with => "''id=#{task.id}''" )) %>It worked, thanks!> Do you really need that :with option if the :url has the :id already?I can''t seem to get the passing of the ID to the RJS-template to work otherwise. My RJS-template looks like this: page["task_#{params[:id]}"].toggle_class_name "completed" Is there another way? Thanks again! -- 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 Oct 11, 2007, at 5:28 AM, Gustav Stockholm wrote:> Rob Biedenharn wrote: >> ... which you can overcome by giving an :object option: >> >> <%= check_box(''task'', ''completed'', :object => task, >> :onchange => remote_function( >> :url => { :action => ''toggle_completed'', :id => task }, >> :with => "''id=#{task.id}''" )) %> > > It worked, thanks! > >> Do you really need that :with option if the :url has the :id already? > > I can''t seem to get the passing of the ID to the RJS-template to work > otherwise. My RJS-template looks like this: > > page["task_#{params[:id]}"].toggle_class_name "completed" > > Is there another way? Thanks again!Does the url get generated with :url => { :action => ''toggle_completed'', :id => task }, put the task id in somewhere? If your routes are set up, then I''d expect that you''d only be redundant with the explicit ?id= from the :with. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---