Hi everyone, I have an app in which I am attempting to add a blog to. I have the blog and commenting system working. It has 2 tables: 1: blogposts (stores the actual blog topics/stories) 2: blogcomments (stores the comments for each blog created) so - I''ve been playing around with the layout, as I think having the most recent posts at the top would be more logical. Below is the code I have which creates the comment: (and attempts to order the comments accordingly) def comment @blogcomment = Blogcomment.find(:all, :order => "created_at desc") @user = User.find(session[:user_id]) Blogpost.find(params[:id]).blogcomments.create(params[:comment]) flash[:notice] = "Added your comment" redirect_to :action => "show", :id => params[:id] end Any ideas? Thanks for reading... -- 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.
take a gander at the development.log - find that sql query that is being generated by that find. Try that query on your DBMS and see if it returns the blogposts in the order you expect. On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi everyone, > > I have an app in which I am attempting to add a blog to. > > I have the blog and commenting system working. It has 2 tables: > > 1: blogposts (stores the actual blog topics/stories) > 2: blogcomments (stores the comments for each blog created) > > so - I''ve been playing around with the layout, as I think having the > most recent posts at the top would be more logical. > > Below is the code I have which creates the comment: (and attempts to > order the comments accordingly) > > def comment > @blogcomment = Blogcomment.find(:all, :order => "created_at > desc") > > @user = User.find(session[:user_id]) > > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) > flash[:notice] = "Added your comment" > redirect_to :action => "show", :id => params[:id] > > end > > Any ideas? > > Thanks for reading... > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hmm, for some reason the log isn''t showing the order by clause: Rendering blogposts/show [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM `blogcomments` [0m Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ blogposts/17] On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> take a gander at the development.log - find that sql query that is > being generated by that find. Try that query on your DBMS and see if > it returns the blogposts in the order you expect. > > On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie > > > > <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi everyone, > > > I have an app in which I am attempting to add a blog to. > > > I have the blog and commenting system working. It has 2 tables: > > > 1: blogposts (stores the actual blog topics/stories) > > 2: blogcomments (stores the comments for each blog created) > > > so - I''ve been playing around with the layout, as I think having the > > most recent posts at the top would be more logical. > > > Below is the code I have which creates the comment: (and attempts to > > order the comments accordingly) > > > def comment > > @blogcomment = Blogcomment.find(:all, :order => "created_at > > desc") > > > @user = User.find(session[:user_id]) > > > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) > > flash[:notice] = "Added your comment" > > redirect_to :action => "show", :id => params[:id] > > > end > > > Any ideas? > > > Thanks for reading... > > > -- > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
it has to - it shows every query On Wed, Jul 7, 2010 at 3:25 PM, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmm, > > for some reason the log isn''t showing the order by clause: > > Rendering blogposts/show > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM > `blogcomments` [0m > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ > blogposts/17] > > > > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> take a gander at the development.log - find that sql query that is >> being generated by that find. Try that query on your DBMS and see if >> it returns the blogposts in the order you expect. >> >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie >> >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi everyone, >> >> > I have an app in which I am attempting to add a blog to. >> >> > I have the blog and commenting system working. It has 2 tables: >> >> > 1: blogposts (stores the actual blog topics/stories) >> > 2: blogcomments (stores the comments for each blog created) >> >> > so - I''ve been playing around with the layout, as I think having the >> > most recent posts at the top would be more logical. >> >> > Below is the code I have which creates the comment: (and attempts to >> > order the comments accordingly) >> >> > def comment >> > @blogcomment = Blogcomment.find(:all, :order => "created_at >> > desc") >> >> > @user = User.find(session[:user_id]) >> >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> > flash[:notice] = "Added your comment" >> > redirect_to :action => "show", :id => params[:id] >> >> > end >> >> > Any ideas? >> >> > Thanks for reading... >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
what I mean is that the orderby isn''t been used. the latest entry in the log just shows the select query without the order by. On 7 July, 21:28, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> it has to - it shows every query > > On Wed, Jul 7, 2010 at 3:25 PM, RubyonRails_newbie > > > > <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hmm, > > > for some reason the log isn''t showing the order by clause: > > > Rendering blogposts/show > > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM > > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m > > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM > > `blogcomments` [0m > > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ > > blogposts/17] > > > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> take a gander at the development.log - find that sql query that is > >> being generated by that find. Try that query on your DBMS and see if > >> it returns the blogposts in the order you expect. > > >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie > > >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > Hi everyone, > > >> > I have an app in which I am attempting to add a blog to. > > >> > I have the blog and commenting system working. It has 2 tables: > > >> > 1: blogposts (stores the actual blog topics/stories) > >> > 2: blogcomments (stores the comments for each blog created) > > >> > so - I''ve been playing around with the layout, as I think having the > >> > most recent posts at the top would be more logical. > > >> > Below is the code I have which creates the comment: (and attempts to > >> > order the comments accordingly) > > >> > def comment > >> > @blogcomment = Blogcomment.find(:all, :order => "created_at > >> > desc") > > >> > @user = User.find(session[:user_id]) > > >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) > >> > flash[:notice] = "Added your comment" > >> > redirect_to :action => "show", :id => params[:id] > > >> > end > > >> > Any ideas? > > >> > Thanks for reading... > > >> > -- > >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
that can''t be - either your syntax is incorrect and it shows an error in the log and on the screen, or it is correct and it shows the SELECT with the ORDER clause. Your syntax appears to be correct, by the way. On Wed, Jul 7, 2010 at 3:30 PM, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what I mean is that the orderby isn''t been used. > > the latest entry in the log just shows the select query without the > order by. > > On 7 July, 21:28, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> it has to - it shows every query >> >> On Wed, Jul 7, 2010 at 3:25 PM, RubyonRails_newbie >> >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hmm, >> >> > for some reason the log isn''t showing the order by clause: >> >> > Rendering blogposts/show >> > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM >> > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m >> > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM >> > `blogcomments` [0m >> > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ >> > blogposts/17] >> >> > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> take a gander at the development.log - find that sql query that is >> >> being generated by that find. Try that query on your DBMS and see if >> >> it returns the blogposts in the order you expect. >> >> >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hi everyone, >> >> >> > I have an app in which I am attempting to add a blog to. >> >> >> > I have the blog and commenting system working. It has 2 tables: >> >> >> > 1: blogposts (stores the actual blog topics/stories) >> >> > 2: blogcomments (stores the comments for each blog created) >> >> >> > so - I''ve been playing around with the layout, as I think having the >> >> > most recent posts at the top would be more logical. >> >> >> > Below is the code I have which creates the comment: (and attempts to >> >> > order the comments accordingly) >> >> >> > def comment >> >> > @blogcomment = Blogcomment.find(:all, :order => "created_at >> >> > desc") >> >> >> > @user = User.find(session[:user_id]) >> >> >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> >> > flash[:notice] = "Added your comment" >> >> > redirect_to :action => "show", :id => params[:id] >> >> >> > end >> >> >> > Any ideas? >> >> >> > Thanks for reading... >> >> >> > -- >> >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 July 2010 21:25, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmm, > > for some reason the log isn''t showing the order by clause: > > Rendering blogposts/show > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM > `blogcomments` [0m > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ > blogposts/17]You are looking at the wrong query. That is the one for Blogpost.find(params[:id]).... The one you have sorted is @blogcomment = Blogcomment.find(:all, :order => "created_at desc") which should appear above that one. You have not specified a sort in the Blogpost query. Colin> > > > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> take a gander at the development.log - find that sql query that is >> being generated by that find. Try that query on your DBMS and see if >> it returns the blogposts in the order you expect. >> >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie >> >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hi everyone, >> >> > I have an app in which I am attempting to add a blog to. >> >> > I have the blog and commenting system working. It has 2 tables: >> >> > 1: blogposts (stores the actual blog topics/stories) >> > 2: blogcomments (stores the comments for each blog created) >> >> > so - I''ve been playing around with the layout, as I think having the >> > most recent posts at the top would be more logical. >> >> > Below is the code I have which creates the comment: (and attempts to >> > order the comments accordingly) >> >> > def comment >> > @blogcomment = Blogcomment.find(:all, :order => "created_at >> > desc") >> >> > @user = User.find(session[:user_id]) >> >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> > flash[:notice] = "Added your comment" >> > redirect_to :action => "show", :id => params[:id] >> >> > end >> >> > Any ideas? >> >> > Thanks for reading... >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try this - check that you are not calling the find somewhere else. If necessary, be sure and put a debugger break point and see what code is really executing. On 7/7/10, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what I mean is that the orderby isn''t been used. > > the latest entry in the log just shows the select query without the > order by. > > On 7 July, 21:28, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> it has to - it shows every query >> >> On Wed, Jul 7, 2010 at 3:25 PM, RubyonRails_newbie >> >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Hmm, >> >> > for some reason the log isn''t showing the order by clause: >> >> > Rendering blogposts/show >> > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM >> > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m >> > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM >> > `blogcomments` [0m >> > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ >> > blogposts/17] >> >> > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> take a gander at the development.log - find that sql query that is >> >> being generated by that find. Try that query on your DBMS and see if >> >> it returns the blogposts in the order you expect. >> >> >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hi everyone, >> >> >> > I have an app in which I am attempting to add a blog to. >> >> >> > I have the blog and commenting system working. It has 2 tables: >> >> >> > 1: blogposts (stores the actual blog topics/stories) >> >> > 2: blogcomments (stores the comments for each blog created) >> >> >> > so - I''ve been playing around with the layout, as I think having the >> >> > most recent posts at the top would be more logical. >> >> >> > Below is the code I have which creates the comment: (and attempts to >> >> > order the comments accordingly) >> >> >> > def comment >> >> > @blogcomment = Blogcomment.find(:all, :order => "created_at >> >> > desc") >> >> >> > @user = User.find(session[:user_id]) >> >> >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> >> > flash[:notice] = "Added your comment" >> >> > redirect_to :action => "show", :id => params[:id] >> >> >> > end >> >> >> > Any ideas? >> >> >> > Thanks for reading... >> >> >> > -- >> >> > 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 >> >> > athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group >> > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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. > >-- Sent from my mobile device -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ah yes... :-) It is in the log: 0mSELECT * FROM `blogcomments` ORDER BY created_at desc LIMIT 1 So if it is in the log, why isn''t it ordering the comments? On 7 July, 21:42, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 7 July 2010 21:25, RubyonRails_newbie <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hmm, > > > for some reason the log isn''t showing the order by clause: > > > Rendering blogposts/show > > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM > > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m > > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM > > `blogcomments` [0m > > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ > > blogposts/17] > > You are looking at the wrong query. That is the one for > Blogpost.find(params[:id]).... > The one you have sorted is > @blogcomment = Blogcomment.find(:all, :order => "created_at desc") > which should appear above that one. > You have not specified a sort in the Blogpost query. > > Colin > > > > > > > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> take a gander at the development.log - find that sql query that is > >> being generated by that find. Try that query on your DBMS and see if > >> it returns the blogposts in the order you expect. > > >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie > > >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > Hi everyone, > > >> > I have an app in which I am attempting to add a blog to. > > >> > I have the blog and commenting system working. It has 2 tables: > > >> > 1: blogposts (stores the actual blog topics/stories) > >> > 2: blogcomments (stores the comments for each blog created) > > >> > so - I''ve been playing around with the layout, as I think having the > >> > most recent posts at the top would be more logical. > > >> > Below is the code I have which creates the comment: (and attempts to > >> > order the comments accordingly) > > >> > def comment > >> > @blogcomment = Blogcomment.find(:all, :order => "created_at > >> > desc") > > >> > @user = User.find(session[:user_id]) > > >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) > >> > flash[:notice] = "Added your comment" > >> > redirect_to :action => "show", :id => params[:id] > > >> > end > > >> > Any ideas? > > >> > Thanks for reading... > > >> > -- > >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 July 2010 21:46, RubyonRails_newbie <craigwesty79-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ah yes... :-) > > It is in the log: > > 0mSELECT * FROM `blogcomments` ORDER BY created_at desc LIMIT 1 > > So if it is in the log, why isn''t it ordering the comments?What is it that seems to not be sorted? @blogcomment should be sorted but you have done nothing to sort blogposts.comments. Have you tried breaking in after the find to inspect the data as suggested by another post? By the way could you avoid top posting please, it is easier to follow the thread if replies are inserted into the previous mail. Colin> > On 7 July, 21:42, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 7 July 2010 21:25, RubyonRails_newbie <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hmm, >> >> > for some reason the log isn''t showing the order by clause: >> >> > Rendering blogposts/show >> > [4;35;1mBlogcomment Load (0.4ms) [0m [0mSELECT * FROM >> > `blogcomments` WHERE (`blogcomments`.blogpost_id = 17) [0m >> > [4;36;1mBlogcomment Columns (1.3ms) [0m [0;1mSHOW FIELDS FROM >> > `blogcomments` [0m >> > Completed in 133ms (View: 54, DB: 8) | 200 OK [http://localhost/ >> > blogposts/17] >> >> You are looking at the wrong query. That is the one for >> Blogpost.find(params[:id]).... >> The one you have sorted is >> @blogcomment = Blogcomment.find(:all, :order => "created_at desc") >> which should appear above that one. >> You have not specified a sort in the Blogpost query. >> >> Colin >> >> >> >> >> >> > On 7 July, 21:15, Jason Michael <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> take a gander at the development.log - find that sql query that is >> >> being generated by that find. Try that query on your DBMS and see if >> >> it returns the blogposts in the order you expect. >> >> >> On Wed, Jul 7, 2010 at 3:07 PM, RubyonRails_newbie >> >> >> <craigwest...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hi everyone, >> >> >> > I have an app in which I am attempting to add a blog to. >> >> >> > I have the blog and commenting system working. It has 2 tables: >> >> >> > 1: blogposts (stores the actual blog topics/stories) >> >> > 2: blogcomments (stores the comments for each blog created) >> >> >> > so - I''ve been playing around with the layout, as I think having the >> >> > most recent posts at the top would be more logical. >> >> >> > Below is the code I have which creates the comment: (and attempts to >> >> > order the comments accordingly) >> >> >> > def comment >> >> > @blogcomment = Blogcomment.find(:all, :order => "created_at >> >> > desc") >> >> >> > @user = User.find(session[:user_id]) >> >> >> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> >> > flash[:notice] = "Added your comment" >> >> > redirect_to :action => "show", :id => params[:id] >> >> >> > end >> >> >> > Any ideas? >> >> >> > Thanks for reading... >> >> >> > -- >> >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
RubyonRails_newbie wrote:> def comment > @blogcomment = Blogcomment.find(:all, :order => "created_at > desc")I don''t understand the point to this. See next comment...> @user = User.find(session[:user_id])Nor this...> > Blogpost.find(params[:id]).blogcomments.create(params[:comment]) > flash[:notice] = "Added your comment" > redirect_to :action => "show", :id => params[:id]Here you are unconditionally redirecting to :action => "show" so what''s the point of the above fetch of Blogcomment?> endBy the way, this method is trying to do too much. - It''s fetching an array of Blogcomments (that it doesn''t seem to do anything with) - It finds a user (and doesn''t seem to use it either) - It finds a Blogpost and creates a new Blogcomment on it. - It sets flash[:notice] - And finally redirects to the "show" action The only effective thing it does should be handled by the Blogcomment''s "create" method anyway. At least in the modern RESTful Rails world. You have written a custom method for something that can be easily handled by the basic CRUD actions of RESTful controllers. The redirect_to will create a new request/response cycle causing all instance variables set in this method to be freed for garbage collection. -- 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-/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.
RubyonRails_newbie wrote:> ah yes... :-) > > It is in the log: > > 0mSELECT * FROM `blogcomments` ORDER BY created_at desc LIMIT 1 > > So if it is in the log, why isn''t it ordering the comments?''LIMIT 1'' at the end of that SQL query means that only one record is being returned. Either you haven''t found the right query in the log, or something in the Blogcomment model is preventing more records being returned via a find(:all). -- 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-/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 7 July 2010 21:59, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> RubyonRails_newbie wrote: >> def comment >> @blogcomment = Blogcomment.find(:all, :order => "created_at >> desc") > > I don''t understand the point to this. See next comment... > >> @user = User.find(session[:user_id]) > > Nor this... > >> >> Blogpost.find(params[:id]).blogcomments.create(params[:comment]) >> flash[:notice] = "Added your comment" >> redirect_to :action => "show", :id => params[:id] > > Here you are unconditionally redirecting to :action => "show" so what''s > the point of the above fetch of Blogcomment? > >> end > > By the way, this method is trying to do too much. > > - It''s fetching an array of Blogcomments (that it doesn''t seem to do > anything with) > - It finds a user (and doesn''t seem to use it either) > - It finds a Blogpost and creates a new Blogcomment on it. > - It sets flash[:notice] > - And finally redirects to the "show" action > > The only effective thing it does should be handled by the Blogcomment''s > "create" method anyway. > At least in the modern RESTful Rails world. You have written a custom > method for something that can be easily handled by the basic CRUD > actions of RESTful controllers. > > The redirect_to will create a new request/response cycle causing all > instance variables set in this method to be freed for garbage > collection.Robert is correct of course, I had missed the redirect_to. A case of woods and trees I think. OP - if what you are trying to to is _always_ sort the comments in that order then consider providing a default_scope on the comments model. Then they will always be so sorted without any extra work on your part, even when you access them as blogpost.comments for example. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.